我想要这种效果:
所以无论我点击哪里,它都会使用子弹产生炸弹类型。到目前为止,这是我的代码。现在它只在鼠标的方向上创建子弹。对不起,如果代码是混乱的。
shotDex = new Timer(timerDelay2);
shotDex.addEventListener(TimerEvent.TIMER, shot);
stage.addEventListener(MouseEvent.MOUSE_DOWN, shootBullet);
stage.addEventListener(MouseEvent.MOUSE_UP, dontShoot);
public var angleRadian = Math.atan2(mouseY + 42.75,mouseX + 331.7);
public var angleDegree = angleRadian * 180 / Math.PI;
public var speed1:int = 10;
public var shotDex:Timer;
public var timerDelay2:int = (250);
public function shot(tEvt:TimerEvent)
{
var _bullet2:bullet2 = new bullet2;
_bullet2.x = 300;
_bullet2.y = 300;
_bullet2.angleRadian = Math.atan2(mouseY + 42.75,mouseX + 331.7);
_bullet2.addEventListener(Event.ENTER_FRAME, bulletEnterFrame);
stage.addChild(_bullet2);
}
public function shootBullet(evt:MouseEvent)
{
var _bullet2:bullet2 = new bullet2;
_bullet2.x = 300;
_bullet2.y = 300;
_bullet2.angleRadian = Math.atan2(mouseY + 42.75,mouseX + 331.7);
stage.addChild(_bullet2);
_bullet2.addEventListener(Event.ENTER_FRAME, bulletEnterFrame);
shotDex.start();
}
public function bulletEnterFrame(evt:Event)
{
var _bullet2 = evt.currentTarget;
_bullet2.x += Math.cos(_bullet2.angleRadian) * speed1;
_bullet2.y += Math.sin(_bullet2.angleRadian) * speed1;
_bullet2.rotation = _bullet2.angleRadian * 180 / Math.PI;
if (_bullet2.x < 0 || _bullet2.x > 600 || _bullet2.y < 0 || _bullet2.y > 600)
{
stage.removeChild(_bullet2);
_bullet2.removeEventListener(Event.ENTER_FRAME, bulletEnterFrame);
}
}
public function dontShoot(evt:MouseEvent)
{
shotDex.stop();
}