Skip to content

Instantly share code, notes, and snippets.

@IQAndreas
Created January 17, 2012 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IQAndreas/1625219 to your computer and use it in GitHub Desktop.
Save IQAndreas/1625219 to your computer and use it in GitHub Desktop.
Sample code for making an item point towards the mouse
compass.rotation = Math.atan2(event.stageY - compass.y, event.stageX - compass.x) * (180/Math.PI) + 90;
//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