1
System / Re: Framerate regulation question
« on: January 31, 2018, 08:35:41 pm »
I'm not sure i understand your question. I'll redirect you to the article that helped me understand, it really is a good read on the subject. It starts from what I told you and there's more after.
http://gameprogrammingpatterns.com/game-loop.html
Now I realize that the frameTime variable in my example is poorly named. It should have been timeElapsed because it represents how much time the game loop took to execute and render.
16.67 ms is the time the frame should take to have 60 of them in a second. (16.67 * 60 = 1000.2 ms)
So if your game loop took 4 ms, you should sleep 16.67 - 4 = 12.67 ms until the next frame, thus enforcing 60 fps.
EDIT : You will realize with more reading on the subject that the sleep method is not exact so it's pretty hard to have EXACTLY 60fps. With this method you'll have around 59 - 61 fps. close enough
http://gameprogrammingpatterns.com/game-loop.html
Now I realize that the frameTime variable in my example is poorly named. It should have been timeElapsed because it represents how much time the game loop took to execute and render.
16.67 ms is the time the frame should take to have 60 of them in a second. (16.67 * 60 = 1000.2 ms)
So if your game loop took 4 ms, you should sleep 16.67 - 4 = 12.67 ms until the next frame, thus enforcing 60 fps.
EDIT : You will realize with more reading on the subject that the sleep method is not exact so it's pretty hard to have EXACTLY 60fps. With this method you'll have around 59 - 61 fps. close enough