timing

Started by
5 comments, last by shiftytitan702 20 years, 11 months ago
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
Advertisement
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

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.
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.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
thanks guys, i appreciate all the help
If you want really accurate movement, check my method in this post:

http://gamedev.net/community/forums/topic.asp?whichpage=1&pagesize=20&topic_id=152750


--Vic--

The future of 2D game development:
Flat Red Ball
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
Rob Loach [Website] [Projects] [Contact]

This topic is closed to new replies.

Advertisement