Apr
24
2009

Simple ease function example

Sometimes there is no need to use heavy tweening libraries if you want to create just a simple easing motion from point A to point B.

obj.x += (targetPosX - obj.x) * .1;
 
if (Math.abs(targetPosX - obj.x) < 1)
{
   //reached a destination so remove listener or tweening function
}

 

And another ease example with acceleration:

velX += (targetPosX - obj.x) * .01;
velX *= .9;
 
obj.x += velX;
 
if(Math.abs(targetPosX - obj.x) < 1)
{
   //reached a destination so remove listener or tweening function
}

 

Comments 

 
0 #1 sn0w 2011-11-19 10:50
Cool. Used that in my JS project.
Quote
 

AS3 Tips

Follow me on Twitter