Controlling game loop speed

Started by
9 comments, last by SimonForsman 10 years, 11 months ago

If you don't want to change much:

Just use a simple(not optimal, but very simple) fixed timestep then: (If you want to do it properly, read this: http://gafferongames.com/game-physics/fix-your-timestep/ )

add:

double currentTime, lastTime;

const double timePerFrame = 16.66667; //60 updates per second, roughly

currentTime = lastTime = systemfunctiontogetcurrenttimeaccuratly();

before your main loop.

and

currentTime = systemfunctiontogetcurrenttimeaccuratly();

if (currentTime - lastTime < timePerFrame) continue;

lastTime+=timePerFrame;

//update and render normally here

at the top of your mainloop (inside the loop, just after the while)

set timePerFrame to whatever makes your game run at the speed you want.

[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

This topic is closed to new replies.

Advertisement