Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Zeke

Slowing things down?

This topic is 6335 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
The simplest thing is to put in a Sleep(someAmount) between changing animation frame, the right thing however is to count deltatimes, like this:

    
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!