Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / I need functions for ease-in/ease-out and overshoot.

Author
Message
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 12th May 2012 20:18
I have zero math skills, but I'd like to have a sprite start off the screen at the top, then move to the center, but slowing to a stop. And also overshooting the destination, "rebounding" up past it, then back down to the final destination.

Another cool function would be a sprite that starts off at zero size, then grows to 110% size, and then shrinks to 100%, kind of popping onto the screen.

I've looked at the Hermite and Lerp functions in the UCF, but like I said, I have zero math, and I couldn't get them to ease a sprite onto the screen.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 12th May 2012 22:10 Edited at: 12th May 2012 22:11
I would use the berp function for this:


I'm guessing from looking at this that for your first problem you would use a "startValue" of zero (Top of the screen in Y), an "endValue" of the centre of the screen in Y (IE. 50(percent) or 240(pixels)). "value" would be the current moment in time taken from the "timer()" command. You might need to play with multiplying that value up or down to get it working right but it should work.

I hope that helps. If I get time I'll do some tests!

EDIT: You'll need the clamp function too

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 12th May 2012 23:49
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 13th May 2012 03:31
Thanks for the info. Can you show me how the functions would be used? That's what I'm not getting, how to use the functions to move a sprite.

For that berp function, would I pass the start y value, the destination y value and the speed? Then the return is the next y value? Do I move the sprite to the returned value, then loop the function again and again until the return value is equal to the destination y value?

I'll try that, but what I've tried so far doesn't move the sprite at all.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 13th May 2012 10:52
Quote: "For that berp function, would I pass the start y value, the destination y value and the speed? Then the return is the next y value? Do I move the sprite to the returned value, then loop the function again and again until the return value is equal to the destination y value?"

That's what I would expect but the third value should be elapsed time. Play with that figure to change the speed.

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 13th May 2012 20:51
Baxslash is right.

For example 0 is your start position, and 100 is your end position.

So if you want your sprite to stop after 3 seconds, then after 1.5 seconds, you should send 0.5 as your value (half the time).

The return value will probably be about 60 or 70 (your new Y position), because it will be accelerating past a normal linear path.

At a value of about 0.75 (2.25 seconds) you may get your overshoot value, of perhaps 110.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 14th May 2012 12:19 Edited at: 14th May 2012 12:30
Rich, I did a quick mock up for you, the berp function might need playing with to get the exact result you want as it's not very pronounced:


EDIT: I added an "amount" variable to the berp function which allows you to make it more pronounced...

Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 14th May 2012 15:36
Oh, thanks baxslash! That's exactly what I need to understand how the functions work!

I'll certainly give your code a close look.


Thanks again!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 14th May 2012 15:38
No problem Rich

Login to post a reply

Server time is: 2024-05-04 11:58:34
Your offset time is: 2024-05-04 11:58:34