Created
January 17, 2012 06:43
-
-
Save IQAndreas/1625219 to your computer and use it in GitHub Desktop.
Sample code for making an item point towards the mouse
This file contains 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
compass.rotation = Math.atan2(event.stageY - compass.y, event.stageX - compass.x) * (180/Math.PI) + 90; |
This file contains 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
//Get the location of the mouse relative to the compass | |
var dx:Number = event.stageX - compass.x; | |
var dy:Number = event.stageY - compass.y; | |
var radianRotation:Number = Math.atan2(dy, dx); | |
var degreeRotation:Number = radianRotation * (180/Math.PI); | |
//Offset the rotation by 90 degrees to make it show up properly | |
compass.rotation = degreeRotation + 90; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment