Atom Engine

GameLoop

Purpose

GameLoop is a high-level wrapper around a low-level loop system. It encapsulates the creation and management of a game loop that repeatedly executes update and render functions at a fixed timestep. It simplifies starting, stopping, and querying the state of the loop.

Lifecycle

Creation → Update → Destruction

Public API

Internal Behavior

Example

const loop = new GameLoop(
  (dt) => {
    // update game logic
    console.log("update", dt);
  },
  (alpha) => {
    // render frame
    console.log("render", alpha);
  }
);

loop.start();

setTimeout(() => {
  console.log(loop.isRunning()); // true
  loop.stop();
}, 2000);