#### Archived

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

# Slowing things down?

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

## 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 on other sites
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 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

1. 1
2. 2
frob
15
3. 3
4. 4
Rutin
12
5. 5

• 12
• 12
• 58
• 14
• 15
• ### Forum Statistics

• Total Topics
632120
• Total Posts
3004219

×