0
我想要這種效果:在360度傳播中拍攝多顆子彈?
所以,在我點擊,它使得使用子彈炸彈類型 - 影響。 到目前爲止,我的代碼如下。現在它只能在鼠標方向創建子彈。 對不起,如果代碼是混亂的。
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();
}
完美的工作!非常感謝:D –
很高興幫助,@Matt!如果你的問題解決了,你應該接受答案。這也可能適用於您之前的一些問題。 :) – CheeseWarlock