Easing / Tweening

BlitzMax Forums/BlitzMax Programming/Easing / Tweening

Robert Cummings(Posted 2010) [#1]
Hi, I use this:

Function Tween:Float(p1:Float, p2:Float, t:Float)
	Return p1 + t * (p2 - p1)
End Function


Is there a way to adopt it so that I can have a version that speeds up, a version that slows down and a version that both speeds up and slows down?

I'd like to use it to move my object from position (p1) to position (p2) but have it always at a predictable position at time (t).

Using just those 3 variables if possible else I have to re-write half the game .... :S

Any help gratefully recieved!


Jur(Posted 2010) [#2]
If "t" is parametric (goes from 0 to 1) then you can use these functions before return statement:

speeds up/slows down
t=(Sin(-90.0+180*t)+1)/2.0

speeds up
t=1-Sin((1-t) *90)

slows down
t=Sin(t*90)


Czar Flavius(Posted 2010) [#3]
Change an algorithm and you change part of your program, change a data structure and you change your entire program - alas! :(


TWH(Posted 2010) [#4]
Sol's interpolation tutorial might have what you need.

Smoothstep speeds up, then slows down. Here's a demo in Bmax:



Robert Cummings(Posted 2010) [#5]
Thanks guys, thats both just what I'm looking for. Quick question TWH, how do I remove TweenSmooth so I can make it just accelerate or just deaccelerate?


TWH(Posted 2010) [#6]
The two Sin-interpolations Jur posted accel and deaccel. If you want to use smoothstep (x*x * (3-2*x)) you can "raise" the power of v to accelerate from 0 to 1, or use the inverse power to deacelerate. Have a look at Sol's page for a description: http://sol.gfxile.net/interpolation/index.html

Function TweenUp:Float(p1:Float, p2:Float, t:Float)
	Local v# = SmoothStep(t)
	v=v^2 'power of 2.
	Return p1 + v * (p2 - p1)
End Function

Function TweenDown:Float(p1:Float, p2:Float, t:Float)
	Local v# = SmoothStep(t)
	v = 1-(1-v)^2 'InvSquared
	Return p1 + v * (p2 - p1)
End Function



Robert Cummings(Posted 2010) [#7]
Thank you very much for your help everyone, solved my problems, both TWH and Jur have also taught me more about interpolation :)


Armitage 1982(Posted 2010) [#8]
I wrote a few Tweening Interpolations class based on Robert Penner equations here : http://arm42.com/blog/index.php?2009/01/21/25-tweening-interpolations-class

There is a few of them, use it as you like :-)