因此,我正在开发一个游戏,并尝试创建一个指向鼠标的动画片段,此代码有什么问题吗?
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;
}
}
}
您的mouseX
和mouseY
现在相对于对象本身。使用root
的mouseX
和mouseY
属性,而不是,如:
var targetX:int = root.mouseX - this.x;
var targetY:int = root.mouseY - this.y;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句