我一直有一個問題,我一直在努力多小時,現在沒有運氣。我有移動綁定到箭頭鍵,用戶通過鼠標環顧四周。當我開槍時,我希望它繼續沿着它最初開始的方向繼續前進,但是如果用戶移動鼠標,子彈就會隨着它改變方向。鼠標移動列表中的子彈
var myTimer2:Timer = new Timer(50);
var list:Array = new Array();
myTimer2.addEventListener(TimerEvent.TIMER, timerListener2);
myTimer2.start();
stage.addEventListener(MouseEvent.CLICK, shoot);
function shoot(shooteven:Event)
{
var Create:Bullet = new Bullet();
addChild(Create);
Create.x = player_obj.x;
Create.y = player_obj.y;
list.push(Create);
}
function timerListener2(e:TimerEvent):void
{
moveBullets();
}
function moveBullets():void
{
var target:Bullet;
for (var i:int=0; i<list.length; i++)
{
target = Bullet(list[i]);
target.currentPlayerRotation = player_obj.rotation;
target.x +=Math.cos((target.currentPlayerRotation)*degreesToRadians) *10;
target.y +=Math.sin((target.currentPlayerRotation)*degreesToRadians) *10;
}
}
這是我在開始時使用「播放器」來跟隨光標的代碼。
stage.addEventListener("mouseMove", Follow);
function Follow(e:MouseEvent):void
{
var a1 = mouseY - player_obj.y;
var b1 = mouseX - player_obj.x;
var radians1 = Math.atan2(a1,b1);
var degrees1 = radians1/(Math.PI/180);
player_obj.rotation = degrees1;
}
我認爲是什麼原因造成的問題是,當我把子彈放入數組他們都共享用戶的影響,移動鼠標,而不是保持其初始值。如果有人對此有任何意見,這將是非常appriciated和長期職位的遺憾。
感謝, 科爾
感謝隊友,這工作完全歡呼。 – 2012-02-01 20:22:01