Friday, July 13, 2007

Simple Easing Formula

// simplest way, but it has a problem
// the movie clip will never reach it's destination and will never stop going
movieclip_mc.onEnterFrame = function(){
movieclip_mc._y += .2 * (newPosition - movieclip_mc._y);
}

// this is how you can snap it into place and stop animating
movieclip_mc.onEnterFrame = function(){
// if the distance between where the mc is and where it's going is less than 1...
if(Math.abs(newPosition - movieclip_mc._y) < 1){
movieclip_mc._y = newPosition; // then snap the mc to it's new position
delete(this.onEnterFrame); // then delete the "onEnterFrame" cuz you don't need it
}else{
movieclip_mc._y += .2 * (newPosition - movieclip_mc._y); // keep going if not
}
}

3 comments:

Nikcardo said...

2007 is a while ago but thanks - works well

Nick

nate said...

Oh yeah, that little formula still holds up. Glad it helped ya out.

ric said...

thanks.
truly helpfully