1
基本上發生的是當我射擊子彈時,它會創建子彈。但是,如果在子彈仍然在屏幕上時再次點擊,它將刪除子彈並創建一個全新的子彈。所以現在一次只能有一顆子彈出現在屏幕上。我該如何解決? 庫中的子彈有「子彈」不止一顆子彈不能同時在屏幕上顯示?
package
{
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 var speed1:int = 10;
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 function bulletEnterFrame(evt:Event)
{
var _bullet1 = evt.currentTarget;
_bullet1.x += Math.cos(_bullet1.angleRadian) * speed1;
_bullet1.y += Math.sin(_bullet1.angleRadian) * speed1;
_bullet1.rotation = _bullet1.angleRadian*180/Math.PI;
if (_bullet1.x < 0 || _bullet1.x > 600 || _bullet1.y < 0 || _bullet1.y > 600)
{
removeChild(_bullet1);
_bullet1.removeEventListener(Event.ENTER_FRAME, bulletEnterFrame);
}
}
}
}