Advertisement

Timing

Started by January 17, 2001 09:55 AM
1 comment, last by Running_Wolf 23 years, 10 months ago
I wish to make it so that, within reason, no matter what the speed of the computer and no matter what the framerate is I can keep my program running at a constant, predictable rate. Did that make sense to anybody? Say that I wish to move forward 0.2 units in a second. I think that I shouls do the following: 0.2/FPS. FPS being the framerate in frames per second. And then I use the answer to that as the amount to move. Do this each cycle through the loop. Am I on the right track?
L.I.G. == Life Is Good
yup! I think tut 23 has something on that.
Advertisement
What I do is every time I call DrawGL() I get the current system time (the exact way to do this will vary from os to os) In Windows it''s GetSystemTime(). I compare this to the result of the last call to find how long it''s been then scale movement proportionatly.

DrawGL(){
int time = GetTheTime(); // get time in ms
int timediff = lasttime - time;
lasttime = time;

move((timediff / 1000.0) * Speed);

------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]

This topic is closed to new replies.

Advertisement