🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

timer based movement VERY inconsistent with ipicture basecode

Started by
1 comment, last by coderTrevor 17 years, 2 months ago
I'm trying to use the IPicture basecode to animate my scene based on the time that has passed. The code works as expected, with my objects falling like gravity is acting on them, but windowed mode has the objects moving 2-3x faster than fullscreen, even though I'm basing movement on nothing but the amount of time passed since the last update. The animation will also slow down if I make the scene complex enough, although I can't see the difference between a simple scene and a moderately complex scene. Right now I'm just drawing one object which represents a rainstorm. The rainstorm object keeps track of the positions and speeds of individual drops. I can change the amount of drops to change the complexity of the scene. Here's my code: I only made one modification to the Update() function. void Update (float milliseconds) // Perform Motion Updates Here { ... TheRain.Animate( milliseconds ); } and my animate function looks like this: void rain::Animate(GLfloat milliseconds) { for( int i = 0; i < numDrops; i++) { // apply acceleration ( only applies to downward velocity) drops.speed += acceleration / milliseconds * 1000; // now move object based on it's velocity drops.y -= drops.speed; DropLogic(i); // check for collisions } } Animate is only called from Update() and the speed of the drops is only changed in Animate(). Acceleration is constant. I can't figure this out for the life of me! Can anyone please help?
Advertisement
change
drops.speed += acceleration / milliseconds * 1000;
to
drops.speed += acceleration *( milliseconds / 1000);
(you might have to adjust acceleration to a sane number, 9.80665 is good for gravity)

and
drops.y -= drops.speed;
should be
drops.y -= drops.speed*( milliseconds / 1000);
Oh wow, can't believe I missed that. Boy, do I feel silly. Thanks a lot for your quick reply and willingness to help a rank n00b, it works perfectly now.

This topic is closed to new replies.

Advertisement