Skip to content
Jirka Dell'Oro-Friedl edited this page Dec 18, 2021 · 4 revisions

Heartbeat

The loop, also game-loop, is the heart of applications that rely on frequent rendering of scenes to create moving visuals. That is not the case for all games, but many. The loop dispatches a LOOP_FRAME event with every beat to all registered consumers. The desired framerate is adjustable and can be based on different time instances. The default setup is tying the framerate to the browsers animation-request functionality and base the timing on Time.game.

Loop modes

  • FRAME_REQUEST: Loop cycles controlled by window.requestAnimationFrame. If the window loses focus, the loop is paused and continues, when it gains focus again. Be aware of the time that might have passed in between.
  • TIME_GAME: Loop cycles with the given framerate using Time.game
  • TIME_REAL: Loop cycles with the given framerate in realtime, independent of Time.game