Rotate an Item based on Mouse Position


/ Published in: ActionScript 3
Save to your folder(s)

This is a simple snippet to rotate an item with the mouse\'s position at a fixed point.


Copy this code and paste it in your HTML
  1. // "rota" is your movieclip/sprite
  2.  
  3. var dx : Number;
  4. var dy : Number;
  5.  
  6. stage.addEventListener( Event.ENTER_FRAME, checkMouse );
  7.  
  8. function checkMouse( evt : Event ) : void
  9. {
  10. dx = mouseX - rota.x;
  11. dy = mouseY - rota.y;
  12. rota.rotation = (Math.atan2(dy, dx) * 180 / Math.PI);
  13. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.