public class GameEnter extends MovieClip
{
public function GameEnter()
{
addEventListener(MouseEvent.MOUSE_DOWN, shootBullet);
}
public var _bullet1:bullet = new bullet;
public var angleRadian = Math.atan2(mouseY - 300,mouseX - 300);
public var angleDegree = angleRadian * 180 / Math.PI;
public function shootBullet(evt:MouseEvent)
{
_bullet1.x = 300;
_bullet1.y = 300;
_bullet1.angleRadian = Math.atan2(mouseY - 300,mouseX -300);
_bullet1.addEventListener(Event.ENTER_FRAME, bulletEnterFrame);
addChild(_bullet1);
}
public var speed1:int = 10;
public function bulletEnterFrame(evt:Event)
{
_bullet1.x += Math.cos(_bullet1.angleRadian) * speed1;
_bullet1.y += Math.sin(_bullet1.angleRadian) * speed1;
_bullet1.rotation = _bullet1.angleRadian*180/Math.PI;
checkHit();
if (_bullet1.x < 0 || _bullet1.x > 600 || _bullet1.y < 0 || _bullet1.y > 600)
{
removeChild(_bullet1);
_bullet1.removeEventListener(Event.ENTER_FRAME, bulletEnterFrame);
}
}
public function checkHit()
{
if(_bullet.hitTestObject(enemy))
{
trace("Enemy hit");
}
}
}
基本上发生的事情是它打印出大约 10 次“Enemy hit”。我想知道:我怎样才能让它只追踪一次“敌人击中”?我认为问题在于,对于子弹在敌人身上的每一帧,它都会打印出来,我该如何解决这个问题,只打印一次?
我最终将替换 "trace("Enemy hit");" 有功能什么的。