Archived

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

Recommended Posts

hi, i would like a simple example/tutorial of how to use timing, to ensure that my graphix wont run extremly fast on somesystems, while, my own would be normal speed. thankyou

Share this post


Link to post
Share on other sites
simple hey...

at the start to your frame loop have something like this

starttime = gettickcount() ;

and at the end

frametime = gettickcount()-starttime ; // time since start
if (frametime < 1000/''insert framerate here'')
sleep(1000/''insert framerate here''-frametime) ; // wait

and thats it.

this is really basic and there are better methods out there. If you were smart you would also replace the sleep() with some preprocessing for the next frame.


Charlie

Share this post


Link to post
Share on other sites
Well, basic maths tells us that...

Distance = Speed * Time.

So first ensure all your sprites / objects have a member variable for speed. Then, when the update function is called for each sprite, they can take the time that has passed since the last update and multiply it by their speed value.

Simple.

Share this post


Link to post
Share on other sites
Sorry, Charlie! m_wherrett''s is the right way.



quote:
Original post by Charlie_246
If you were smart you would also replace the sleep() with some preprocessing for the next frame.



Ummm, if your processing is so fast that you have time left over, then there is no reason to start preprocessing the next frame, because you are going to have time left over in the next frame.

That reminds me of a programming joke: A programmer profiles his code and finds that 80% of the time is spent in an idle function (doing nothing). He decides he needs to write a faster idle function.

Share this post


Link to post
Share on other sites
When moving objects, modify it by multiplying the velocity by the difference of time between the last and current time frames:

cObject.PosX += cObject.SpeedX * TimeDelta



- Rob Loach
Current Project: Go Through Object-Oriented Programming in C++ by Robert Lafore

"Do or do not. There is no try."
- Yoda

Share this post


Link to post
Share on other sites