Custom mouse pointer rotation is erratic
Ok well I'm not really replacing the mouse cursor exactly. Just placing a custom image of a pointer below it so it will follow the mouse cursor as it moves around the screen. I want this pointer image to move with the mouse and to rotate and point in the direction the mouse is traveling. Simple stuff.
The problem is that the rotation of the pointer graphic is not smooth at all. It is jumpy and somewhat erratic particularly at slower mouse speeds. When the mouse is moving quickly the problem seems to go away.
What is going on here?
PHP Code:
package {
import flash.display.Sprite;
import flash.events.*;
public class MouseFollower extends Sprite {
private var pointer:Pointer = new Pointer(); // ...a simple triangle mc
public function MouseFollower() {
addChild(pointer);
stage.addEventListener(MouseEvent.MOUSE_MOVE, enterFrameHandler);
}
private function enterFrameHandler(moved:MouseEvent):void {
var dx:Number = mouseX - pointer.x;
var dy:Number = mouseY - pointer.y;
var angle:Number = Math.atan2(dy, dx) * (180/Math.PI);
pointer.rotation = angle;
pointer.x = mouseX;
pointer.y = mouseY;
}
}
}