Archived

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

the_grip

Locking a framerate

Recommended Posts

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!"

Share this post


Link to post
Share on other sites
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...


Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.."

Share this post


Link to post
Share on other sites