Locking a framerate

Started by
8 comments, last by the_grip 22 years, 9 months ago
What is a good way to lock in a framerate for a program so that it will run at a consistent speed despite the hardware it''s on? Or is there a better way to handle this type of problem? Thanks! Please be as specific as possible... i''m fairly green at this DX stuff... "You call him Dr. Grip, doll!"
"You call him Dr. Grip, doll!"
Advertisement
a better way is to not lock it. do a search on the forums. this question has been asked a million times and doesn''t need to go in depth here.

HHSDrum@yahoo.com
Polarisoft Home Page
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
This would quickly become a very boring site if all we did was search forums...

You need three variables:

int m_iLastTime
int m_iThisTime and
int m_iTimePassed;

At the begining of your gameloop do this:

m_iLastTime = m_iThisTime;m_iThisTime = timeGetTime();m_iTimePassed = m_iThisTime - m_iLastTime  


That way m_iTimePassed will contain the number of elapsed milliseconds since your last gamepoll.

If you want to move an object (like a spaceship) 50 pixels per. second then do this (this example uses floats):

m_fSpaceShipPosX += 50.0 * ((float)m_iTimePassed /1000.0);  



Oh..One last thing...Before you start your gameloop for the first time you should do this:

m_iThisTime = timeGetTime(); 


Hope this helps you and that there are no errors...


-------------Ban KalvinB !
Check out the timer tutorial on my site.

Ignite Software Ltd.
Thanks both of you all... and granat, i agree

And for the record, i did do a search, but didn''t find anything as straightforward as i wanted, thus this post came into existence (maybe now someone in the future will find what they are looking for).
"You call him Dr. Grip, doll!"
quote:
This would quickly become a very boring site if all we did was search forums...

I agree completely. but why post redundant topics when the same question has been asked and answered within the past 5 days?
I searched frame rates in the past 5 days and got a nice handy link to a thread called "Frame rates" (which btw discusses this)
just a thought.
Joe

HHSDrum@yahoo.com
Polarisoft Home Page

Edited by - Julio on July 25, 2001 1:24:19 PM
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
Isn''t that post about measuring framerate, not handling it?

"You call him Dr. Grip, doll!"
"You call him Dr. Grip, doll!"
I never have much success with the search function..

Sometimes it finds 2 billion topics and sometimes it finds nothing...

-------------Ban KalvinB !
quote:
Isn''t that post about measuring framerate, not handling it?

I don''t completely remember. that''s not the point though. the point is that you can search the forumns. anyways, I don''t want to start a flame war over a trivial topic.
cheers,
Joe

HHSDrum@yahoo.com
Polarisoft Home Page
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
neither should you, you freaking hippy!
Honestly, though yeah posting helps, if you read my other post..(this is what I kinda said):
"Just writing out the question can help clarify and help you find a solution.."

This topic is closed to new replies.

Advertisement