Actionscript 3对象无法转动

时间:2014-11-14 22:19:40

标签: actionscript-3 flash actionscript trigonometry

所以我正在开发一款游戏并尝试创建一个转向指向鼠标的动画片段,这段代码有什么问题吗?

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;
        }
    }

}

1 个答案:

答案 0 :(得分:2)

您的mouseXmouseY现在相对于对象本身。请改用root的{​​{1}}和mouseX属性,例如:

mouseY