[RESOLVED] Bullets in as3
I was wondering if anyone knew how to create bullets in as3?
I have a main character = hero.mc
Basically I need to store the bullets in an array and have them firing from the hero. It sounds simple enough, but for some reason I can't get it to work.
So far I have this:
Quote:
private var bullets:Array;
public function createBullets() {
bullets = new Array();
var bullet = new Object();
bullet.startx = hero.mc.x;
bullet.starty = hero.mc.y;
bullet.width = 10.0;
bullet.height = 10.0;
bullet.moveRight = true;
bullet.walkSpeed = .3;
}
I have have a keyboard function that runs createBullets() when the spacebar is pressed:
Quote:
public function keyDownFunction(event:KeyboardEvent) {
if (gameMode != "play") return;
if (event.keyCode == 37) {
hero.moveLeft = true;
} else if (event.keyCode == 39) {
hero.moveRight = true;
} else if (event.keyCode == 32) {
createBullets();
} else if (event.keyCode == 38) {
if (!hero.inAir) {
hero.jump = true;
}
}
}
Any help would be greatly appreciated :)