Posted By

IsoJon on 07/02/10


Tagged

rotate mouse


Versions (?)

Who likes this?

6 people have marked this snippet as a favorite

Vordreller
Demian
TrentSkunk
adrianparr
davidino1978
scottwatkins


Rotate an Item based on Mouse Position


 / Published in: ActionScript 3
 

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

  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
Posted By: pjdcreative on December 16, 2015

Hi there, I like the code, works well. How would I add some easing to the rotation? so it doesn't stop so abruptly?

You need to login to post a comment.