所以我正在开发一款游戏并尝试创建一个转向指向鼠标的动画片段,这段代码有什么问题吗?
package
{
import flash.display.*;
import flash.events.*;
public class Shark extends Sprite
{
public function Shark()
{
this.x = 300;
this.y = 200;
addEventListener(Event.ENTER_FRAME, playGame);
}
function playGame(event:Event):void
{
var targetX:int = mouseX - this.x;
var targetY:int = mouseY - this.y;
this.rotation = Math.atan2(targetY,targetX) * 180 / Math.PI;
}
}
}
答案 0 :(得分:2)
您的mouseX
和mouseY
现在相对于对象本身。请改用root
的{{1}}和mouseX
属性,例如:
mouseY