SFML community forums

Help => System => Topic started by: Bryston on March 20, 2013, 07:02:33 pm

Title: creating a spin-down timer
Post by: Bryston on March 20, 2013, 07:02:33 pm
Any advice on how to create a spin-down timer?

Ive got an animation running at speed x and i want it to slowly spin down to 0 then stop

im pretty sure it is going to involve three elements like
sf::Clock sysClock;

sf::Time tInitial;
sf::Time tDelta;
sf::Time tTotal;

tInitial = sysClock.restart();
tDelta = sf::Seconds(0.02f);
tTotal = (some math operation combining tInitial and tDelta so i can ramp the animation down)
 

Im using Foalys animation class, so that may have a small/big influence on how to handle this problem.
Title: Re: creating a spin-down timer
Post by: Christopher Jozwiak on March 21, 2013, 07:39:32 pm
I'm not really good an expert on this stuff. But wouldn't you have to either decrease a clocks increments? Not sure but, thought about it.  Makes sense for the moment :)
Title: Re: creating a spin-down timer
Post by: Nexus on March 21, 2013, 08:11:24 pm
thor::Timer (http://www.bromeon.ch/libraries/thor/v2.0/doc/classthor_1_1_timer.html) ;)

But for logical time (as opposed to real time), you often don't want clocks, since they continue running when paused etc. A sf::Time variable that is continuously decreased may already suffice.
Title: Re: creating a spin-down timer
Post by: Lee R on May 02, 2013, 12:00:29 am
In the most general sense, what you're trying to describe is called "interpolation". The 'quadratic ease out' equation fits with the "slowing down" behaviour you're after.

http://gizma.com/easing/#quad2

Unfortunately, frame based animations tend to look like poop when you slow them down, because they cannot generate frames-between-frames. This is the raison d'ĂȘtre for inbetweening, aka tweening.