Hey,
I’m trying to fix my character shooting function/hit test. If I shoot one bullet at an enemy mc then the hit test occurs and the enemy plays the “dead” animation. However if I fire multiple bullets then the hit test wont occur until the last bullet hits. I guess every time I fire a bullet it creates a new instance of the class and any previous instances can’t be called on using bulletVar.
I presume my best bet would be to put each bullet into an array? I’ve no idea how to code this though, any help would be much appreciated!
Here’s the code:
var bulletVar:bullet = new bullet();
stage.addEventListener(KeyboardEvent.KEY_DOWN, downDetect);
function downDetect(event:KeyboardEvent):void
{
if(event.keyCode == Keyboard.SPACE)
{
bulletVar = new bullet();
this.addChild(bulletVar);
if(facingRight || rightDown)
{
bulletVar.x = (ball_mc.x + 253 );
bulletVar.gotoAndPlay("shoot_right");
}
else if(facingLeft || leftDown)
{
bulletVar.x = (ball_mc.x + 203);
bulletVar.gotoAndPlay("shoot_left");
}
}
}
stage.addEventListener(Event.ENTER_FRAME, hitEnemy);
function hitEnemy(event:Event):void
{
if (bulletVar.hitTestObject(enemy_mc))
{
enemy_mc.gotoAndStop(“dead”);
stage.removeEventListener(Event.ENTER_FRAME, hitEnemy);
this.removeChild(bulletVar);
}
}
Thanks
Ryan