Slowing things down?
Ive just managed to make a sprite walk with animation the problem is she walks way to fast (so fast you cant really see the animation).
Can anyone give me an idea on how I can slow her down? Im animating using a linked list if that is any help.
Thanks for your time
Just my thoughts take them as you will.
"People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
The simplest thing is to put in a Sleep(someAmount) between changing animation frame, the right thing however is to count deltatimes, like this:
Here DeltaTime is passed in seconds (or fractions of) so if you want each frame to be displayed for a second you set SomeAmount to 1.0 (all vars except FrameNumber are doubles). AccumulatedDeltaTime must not be declared as auto (that is it must either be a member var if you're using classes (C++), a static var or a global var), thus it must persist between calls to AnimateSprite() (as must FrameNumber).
You get the DeltaTime by doing something like this in your main loop:
Well, that's it in pseudo code. The reason I want the DeltaTime in seconds is that it's more convenient, later when you're about to move the sprite around, you'll want to multiply the velocity with DeltaTime, so your sprite doesn't move too fast.
/Andreas
Edited by - amag on January 16, 2001 8:37:57 AM
void AnimateSprite(double DeltaTime){ AccumulatedDeltaTime += DeltaTime; if(AccumulatedDeltaTime >= SomeAmount) { FrameNumber++; // or some other way to calculate frame AccumulatedDeltaTime = 0.0; } DrawSprite(FrameNumber); // actually depending on your // rendering, this could be put in // the if-block above}
Here DeltaTime is passed in seconds (or fractions of) so if you want each frame to be displayed for a second you set SomeAmount to 1.0 (all vars except FrameNumber are doubles). AccumulatedDeltaTime must not be declared as auto (that is it must either be a member var if you're using classes (C++), a static var or a global var), thus it must persist between calls to AnimateSprite() (as must FrameNumber).
You get the DeltaTime by doing something like this in your main loop:
while(true){ OldTime = ThisTime; ThisTime = timeGetTime(); // return-value in ms // so we must divide to get it in seconds DeltaTime = (double)(ThisTime - OldTime) / 1000; AnimateSprite(DeltaTime);}
Well, that's it in pseudo code. The reason I want the DeltaTime in seconds is that it's more convenient, later when you're about to move the sprite around, you'll want to multiply the velocity with DeltaTime, so your sprite doesn't move too fast.
/Andreas
Edited by - amag on January 16, 2001 8:37:57 AM
Thanks very much
Just my thoughts take them as you will.
"People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
Just my thoughts take them as you will.
"People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement