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.
Creation → Update → Destruction
GameLoop instance is constructed with update and render callbacks. Internally, it initializes loop state via createLoop.update(dt) and render(alpha) functions according to the underlying loop implementation.stop(), which halts execution. The instance itself does not explicitly release resources beyond stopping the loop.update(dt: number): Function called each tick with delta time.render(alpha: number): Function called for rendering interpolation.fixedDelta?: number: Fixed timestep interval (default: 1/60).LoopState object created by createLoop(update, render, fixedDelta).startLoop(state) begins the loop.stopLoop(state) halts the loop.state.running flag is used to determine whether the loop is active.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);
LoopStatecreateLoopstartLoopstopLoop