Jump to content

[SOLVED] I need an ease function


tibberous

Recommended Posts

Here is the header.

 

function ease (startingX, startingY, endingX, endingY, frame, framesTotal, ease){

 

return Array(currentX, currentY);

}

 

Basically it takes 2 sets of points, the starting location of an object and the ending location. It returns the location the object would be at at frame, provided there are framesTotal total frames. Ease simulates easing in or out, causing the object to move slower at the beginning or the end of the function.

 

Anyone know how to write this? I used to know but I forget.

Link to comment
https://forums.phpfreaks.com/topic/62127-solved-i-need-an-ease-function/
Share on other sites

Here, I'll help:

 

function ease (startingX, startingY, endingX, endingY, frame, framesTotal, ease){

currentX = startingX - ( (startingX - endingX) * (frame/framesTotal) );

currentY = startingY - ( (startingY - endingY) * (frame/framesTotal) );

 

return Array(currentX, currentY);

}

 

That works so long as ease is 0. Can someone tell me how to add easing?

function easeTo (startingX, startingY, endingX, endingY, frame, framesTotal, ease){

if(ease > 0) ease = 1 + (ease / 100);

else if(ease < 0) ease = 1 + (ease / 200);

else ease = 1;

currentX = startingX - ( (startingX - endingX) * Math.pow( (frame/framesTotal) , ease) );

currentY = startingY - ( (startingY - endingY) * Math.pow( (frame/framesTotal) , ease) );

 

return Array(currentX, currentY);

}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.