Hey all, I am trying to cap my update loop so it updates the game every 16ms or 60fps.
I've got a time class and I am able to start/stop & get the elapsed time in seconds. Currently its averaging around 0.004. I'm not sure the best way to go about this so could use some help please!
P.S should the render of a game ever be capped? Or just the update, i guess a game should be able to draw everything fast as possible..
In most cases, you should cap the fps to avoid tearing.
The proper way to do it is to wait for vertical synchronization signal, which is generated just after the pixel data is sent to your monitor.
So, you should check the graphics library that you are using (which one are you using?) whether it provides a function that pauses until vsync.
When the vsync signal is generated, the function will exit, and at that point in time you are free to update the screen. Waiting for vsync will automatically cap the framerate to refresh rate of your display device.
I will try what you have suggested with the FPS also. Thanks so much.
Yeah, I'd like to limit the FPS and limit the amount of time the update loop is ran, it was being done every 0.004ms from when I timed how long it took to run through the whole updates.