Created
May 31, 2009 17:52
-
-
Save akio0911/120961 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package{ | |
import flash.display.Sprite; | |
import flash.events.Event; | |
public class RotateToMouse extends Sprite { | |
private 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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment