Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 04-14-2008, 12:18 AM   #1
Wesley008
Registered User
 
Join Date: Apr 2008
Posts: 19
Exclamation [AS2] Ball Stop on Next KeyDown

ActionScript Code:
_global.bspeed = 25; Player.onEnterFrame = function() {     var speed = 3;     var gravity = .5;     if (Key.isDown(Key.UP)) {         Player._y -= speed;     }     if (Key.isDown(Key.DOWN)) {         Player._y += speed;     }     if (Key.isDown(Key.LEFT)) {         Player._x -= speed;     }     if (Key.isDown(Key.RIGHT)) {         Player._x += speed;     }     Bullet._y -= bspeed;     Player._y += gravity; }; keyListen = new Object(); keyListen.onKeyDown = function() {     if (Key.getCode() == Key.SPACE) {         var bulletx = Player._x;         var bullety = Player._y-Player._height+10;         _global.Bullet = attachMovie("mcBullet", "mcBullet", _root.getNextHighestDepth(), {_x:bulletx, _y:bullety});     } }; Key.addListener(keyListen);

Heres my code for the game. Whats happening in this is when I press spacebar it generates the Bullet Movie and positions it at the tip of the Player, Then at the same time it Moves forward for the Bullet Effect but now my problem accors, instead of creating a new bullet to follow the bullet before it, it stops the one in motion and the new one that just created with the Spacebar goes in motion, and so on so forth with each spacebar I press.
Wesley008 is offline   Reply With Quote
Old 04-14-2008, 04:18 AM   #2
ASWC
Super Moderator
 
ASWC's Avatar
 
Join Date: Dec 2007
Location: Greenville, SC
Posts: 6,528
Default

ActionScript Code:
var numberOfBullet:Number = 0; _global.bspeed = 25; Player.onEnterFrame = function() {     var speed = 3;     var gravity = .5;     if (Key.isDown(Key.UP)) {         Player._y -= speed;     }     if (Key.isDown(Key.DOWN)) {         Player._y += speed;     }     if (Key.isDown(Key.LEFT)) {         Player._x -= speed;     }     if (Key.isDown(Key.RIGHT)) {         Player._x += speed;     }     Bullet._y -= bspeed;     Player._y += gravity; }; keyListen = new Object(); keyListen.onKeyDown = function() {     if (Key.getCode() == Key.SPACE) {         numberOfBullet+=1;         var bulletx = Player._x;         var bullety = Player._y-Player._height+10;         _global.Bullet = attachMovie("mcBullet"+numberOfBullet, "mcBullet", _root.getNextHighestDepth(), {_x:bulletx, _y:bullety}); if(numberOfBullet>30)//set the max number of bullet {numberOfBullet=0;}     } }; Key.addListener(keyListen);
__________________
aswebcreations
Super Duper!
ASWC is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bouncing ball class off other class objects Arutha Studios ActionScript 3.0 0 11-29-2007 09:01 AM
Ball won't stop rolling.... sunlis ActionScript 2.0 2 07-02-2006 07:48 PM
How to stop and play movieclips cayohueso ActionScript 2.0 8 07-22-2005 02:53 AM
stop() not working BuffySummers ActionScript 2.0 1 10-30-2003 09:57 AM
Stop a loaded movie doesn't work! AVETAR ActionScript 1.0 (and below) 5 12-06-2002 02:09 AM


All times are GMT. The time now is 03:40 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.