[Tutorial] Flash - Shaking a Movie Clip

Come here to View/Post any tutorials here.
x2i said
Post Mon Feb 23, 2009 4:11 pm
Here is a small function I just made to shake a movie clip like an earthquake.

Place this function on the main timeline:

Code: Select all
function shake_mc(mc, intensity, origx, origy) {
   mc._x = origx;
   mc._y = origy;
   mc.onEnterFrame = function() {
      mc._x = origx+Math.random()*intensity;
      mc._y = origy+Math.random()*intensity;
      if (intensity>0) {
         intensity--;
      }
   };
}


Then add this code to the movie clip you wish to shake - you needn't put the on(press) part if you don't want to but make sure you put it call to the shake somewhere and the origpos part in as this will make the movie clip ultimately return to its original position.

The number 5 represents the intensity of the shake and it will decrease in intensity from that number.

Code: Select all
onClipEvent (load) {
   origpos = {x:_x, y:_y};
}
on (press) {
   _root.shake_mc(this, 5, origpos.x, origpos.y);
}
Signature

Return to Tutorials




Who is online?

Users browsing this forum: No registered users and 0 guests

cron