#### Archived

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

# smooth animation and realistic movement

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

## Recommended Posts

i''ve got my 2D engine up and running. the animation is timed perfectly. the way i have it timed is that when a certain amount of time lapses after the last frame was incremented, it increments the frame value and starts the timer over. it works great on my c466, but on my partner''s p133 it runs slow. i''m guessing that the animation misses some of the rollovers and compensates by incrementing the frame late. now what i''m wondering is, would it be a good idea to have a switch statement testing the difference between the last and current times, like this:
  switch(timer) { case 10: frame = 0; break; case 20: frame = 1; break; case 30: frame = 2; break; ... } 
and so on... would something like that work correctly? i figure that it would make the right frame show up at the right time... about the movement, on different speed computers (same as the case above) the movement runs faster or slower. is there some way i can factor the time into the animation? also, is there some way i can make the animation more real looking, so the sprite doesn''t look like it''s gliding when it''s supposed to be walking? i''ve tried a switch statement testing the frame number and doing the coordinate calculations from there, but that made the movement jerky... thanks for any help, david

##### Share on other sites
If you did it that way, an easier approach may be:

DWORD timeDifference = ... how much time since we checked last ...;mySprite->frame += (timeDifference/animDelay);while (mySprite->frame >= maxFrames) mySprite->frame -= maxFrames;

just set animDelay to how fast you want the animation. This assumes that your first frame is 0.

Edited by - Buster on June 27, 2000 1:20:50 PM

##### Share on other sites
first you calculate the frame rate that the person is getting on their computer. (without locking the frame rate) then you move the objects in accordance with that rate. you could do it mathmatically or you could us a switch statement.

JoeMont001@aol.com

##### Share on other sites
buster:
the way that i handle my frame changing right now is almost the same as you posted. i do something like

DWORD difference = current_time - last_time;if(difference > 100) frame++;last_time = current_time;

i figure that would work the same. am I wrong?

Julio:

how would I calculate it matematically? i could probably figure it out myself, but i'm not at my computer at the moment. i'm at work...

thanks guys,
david

Edited by - neonstar on June 27, 2000 1:33:37 PM