私はあなたの方法に何も悪いことを見つけることができませんでした。次のコードで(ほぼ)逐語的に使用して、マウスを動かしたときにマウスを追跡するスプライトを設定しました。おそらく私が書いたものを見て、それがあなたが持っているコードと異なるかどうかを確認してください。それが失敗した場合は、おそらくあなたがしたことをもっと投稿しますか?
// Creates the sprite that will visually track the mouse.
private function CreateSurvivor() : Sprite
{
// Create a green square with a white "turret".
var shape = new Shape();
shape.graphics.beginFill(0x00FF00);
shape.graphics.drawRect(0, 0, 100, 100);
shape.graphics.beginFill(0xFFFFFF);
shape.graphics.drawRect(50, 45, 50, 10);
shape.graphics.endFill();
// Center the square within its outer container. Allows it to spin
// around its center point.
shape.x = -50;
shape.y = -50;
var survivor = new Sprite();
survivor.addChild(shape);
return survivor;
}
initメソッドは、サバイバーを作成して表示リストに添付するだけです。
private function init(e)
{
m_survivor = CreateSurvivor();
m_survivor.x = 300;
m_survivor.y = 200;
addChild(m_survivor);
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseProcess);
}
そして最後に、あなたの元の方法:
public function mouseProcess(e:MouseEvent) : Void
{
var Xdistance:Float = e.localX - m_survivor.x;
var Ydistance:Float = e.localY - m_survivor.y;
m_survivor.rotation = Math.atan2(Ydistance, Xdistance) * 180 / Math.PI;
}
お役に立てれば。