ActionScript 3对象无法转动

ws

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

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

}
伊凡·切尔尼赫(Ivan Chernykh)

您的mouseXmouseY现在相对于对象本身。使用rootmouseXmouseY属性,而不是,如:

var targetX:int = root.mouseX - this.x;
var targetY:int = root.mouseY - this.y;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章