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
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?

Link to comment
Share on other sites

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);

}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.