您好我在youtube上看了tut并且我编写了这段代码以使对象旋转到鼠标位置,但它有点无法正常工作。
代码:
package {
import flash.display.MovieClip;
import flash.events.Event;
public class char extends MovieClip
{
private var _pointer = this;
public function char()
{
addEventListener(Event.ENTER_FRAME, onEnter);
}
private function onEnter(event:Event):void
{
//Initialize dx and dy variables
var dx:Number = mouseX - _pointer.x;
var dy:Number = mouseY - _pointer.y;
//Store angle in angle variable
var angle:Number = Math.atan2(dy, dx) * 180 / Math.PI;
//Apply angle
_pointer.rotation = angle;
}
}
}
答案 0 :(得分:0)
您需要从父级影片剪辑中获取mouseX和mouseY坐标,因为:
所以你需要修改这两行:
var dx:Number = parent.mouseX-_pointer.x;
var dy:Number = parent.mouseY-_pointer.y;