View Full Version : shooting multiple bullets (AS3)

11-24-2008, 03:45 PM
Hello everyone,
I'm trying to make my platform game character shoot a gun, my character and gun are one movieclip and the bullet is another. The bullet mc starts on a blank frame with a stop() function, when I press the space bar the bullet mc plays from frame 2 which is a motion tween of the bullet quickly moving across the page. I've set the bullet's y and x values relative to the character mc so that the bullet always comes from the gun.

My issue is that if I press the space bar a bullet will fly out of the gun (great!) but if I press the space bar again, the first bullet disappears and the bullet animation starts again. I want to be able to shoot a new bullet every time I press the space bar without effecting the bullets that have already been shot.


if(event.keyCode == Keyboard.SPACE)

bullet_right_mc.y = (ball_mc.y -38);
bullet_right_mc.x = (ball_mc.x + 253);




11-24-2008, 05:51 PM
I would maintain an array of bullets, create a Bullet class, and do something like this:

var newBullet:Bullet = new Bullet(x,y);

11-25-2008, 12:29 AM
Cheers for your help dude.
I added the class bullet and set a var bulletVar:

var bulletVar:bullet = new bullet();
spaceDown = true;
bulletVar.y = (ball_mc.y -38);

Thanks again!