RotateToMouse
/**
* Copyright crossisland ( http://wonderfl.net/user/crossisland )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/cNpa
*/
package {
import flash.display.Sprite;
import flash.events.Event;
public class RotateToMouse extends Sprite {
var arrow:Arrow;
public function RotateToMouse() {
init();
}
private function init():void {
arrow = new Arrow();
addChild(arrow);
arrow.x = stage.stageWidth / 2;
arrow.y = stage.stageHeight / 2;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
public function onEnterFrame(event:Event):void {
var dx:Number = mouseX - arrow.x;
var dy:Number = mouseY - arrow.y;
var radians:Number = Math.atan2(dy, dx);
arrow.rotation = radians * 180 / Math.PI;
}
}
}
import flash.display.Sprite;
class Arrow extends Sprite {
public function Arrow() {
graphics.beginFill(0x000000);
graphics.moveTo(-50, -25);
graphics.lineTo(0, -25);
graphics.lineTo(0, -50);
graphics.lineTo(50, 0);
graphics.lineTo(0, 50);
graphics.lineTo(0, 25);
graphics.lineTo(-50, 25);
graphics.lineTo(-50, -25);
graphics.endFill();
}
}