Instead of relying on explicit sleep behavior or timer-specific platform-specific functions (which may work well, I don't know), you could structure this as a game loop.
Inside the loop, you call a function to give you the current time. You will find out how much has passed since you drew the last frame, and decide when you need to make the next frame at the right time. During development, you should measure the actual number of frames per second and display it.
With this approach, tt is easier to make your cross-platform code more accurate. In addition, your loop manages rather than structuring your code as timer callbacks, which you might also prefer.
The disadvantage is that the βwait waitingβ cycle means that your process will use the processor all the time unnecessarily. To reduce this, you can bring the processor into your loop by explicitly reassigning the user interface events or, possibly, using a shorter sleep :-).
If you want to learn more about this approach, start a search on materials in game cycles.
Here are some important links:
http://www.koonsolo.com/news/dewitters-gameloop/
http://gafferongames.com/game-physics/fix-your-timestep/
And a discussion of SO:
https://gamedev.stackexchange.com/questions/1589/fixed-time-step-vs-variable-time-step
Scrollerblaster
source share