« Go back

Limit your framerate

Per default Dgame does not limit the framerate of your application. But you can do that by calling


This will limit the framerate to the display refresh rate of your current monitor. This is mostly about 60. You can disable (and also enable) it whenever you want to. You can also ask which mode is currently active with


You can see the current FPS with the help of StopWatch and a call to getCurrentFPS inside the Game Loop which measures the framerate in each frame.

Furthermore you can limit the framerate by yourself, again with the help of StopWatch but this time with getTicks / getTime or the static method wait. An example with getTicks and wait:

Show Raw
immutable ubyte FPS = 30;
immutable ubyte TICKS_PER_FRAME = 1000 / FPS;
// ...
StopWatch sw;
// ...
// inside of the Game Loop
if (sw.getElapsedTicks() >= TICKS_PER_FRAME) {
    // Do game logic
    // ...

With the code above, your game logic will be regularly executed with a FPS of 30.

« Go back