I’m writing a game, and I saw the FPS algorithm doesn’t work correctly (when he have to calculate more, he sleeps longer…) So, the question is very simple: how to calculate the sleeptime for having correct FPS?
I know how long it took to update the game one frame in microseconds and of course the FPS I want to reach.
I’m searching crazy for a simple example, but I can’t find one….
The code may be in Java, C++ or pseudo….
The number of microseconds per frame is
1000000 / frames_per_second. If you know that you’ve spentelapsed_microsecondscalculating, then the time that you need to sleep is: