Posted By

burnandbass on 03/15/12


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

shalomfriss
lordsirc


Shake Effect for any DisplayObject


 / Published in: ActionScript 3
 

Use this to make MovieClip "shake"

  1. var tempX:Number = clip.x;
  2. var tempY:Number = clip.y;
  3.  
  4. var shakeTimer:Timer = new Timer(30,10);
  5. shakeTimer.addEventListener(TimerEvent.TIMER, function():void{
  6. clip.x += randomRange(-2,2);
  7. clip.y += randomRange(-2,2);
  8. clip.scaleX = clip.scaleY = randomRange(9,11)/10;
  9. });
  10.  
  11. shakeTimer.addEventListener(TimerEvent.TIMER_COMPLETE, function():void{
  12. clip.x = tempX;
  13. clip.y = tempY;
  14. clip.scaleX = clip.scaleY = 1;
  15. });
  16.  
  17. shakeTimer.start();
  18.  
  19. //internal used for shake effect
  20. public static function randomRange(min:Number, max:Number):Number {
  21. return (min + Math.random() * (max - min));
  22. }

Report this snippet  

You need to login to post a comment.