Skip to content

GameLoop

Defined in: GameLoop.ts:29

Game loop with fixed timestep accumulator.

Driven by an external ticker (e.g., PixiJS Ticker) or manual tick() calls for testing. Implements deterministic fixed updates with variable rendering.

The incoming per-frame delta is wall-clock milliseconds (PixiJS tickers report deltaMS). tick() converts it to seconds once, so every callback downstream receives seconds.

new GameLoop(config?): GameLoop

Defined in: GameLoop.ts:44

GameLoopConfig

GameLoop

readonly fixedTimestep: number

Defined in: GameLoop.ts:31

Fixed timestep in seconds.


readonly maxFixedStepsPerFrame: number

Defined in: GameLoop.ts:33

Max fixed steps per frame.

get frameCount(): number

Defined in: GameLoop.ts:50

Current frame count.

number


get interpolationAlpha(): number

Defined in: GameLoop.ts:60

Ratio of accumulated time to fixed timestep, for physics interpolation.

number


get isRunning(): boolean

Defined in: GameLoop.ts:55

Whether the loop is running.

boolean


get lastTickAt(): number

Defined in: GameLoop.ts:70

Wall-clock timestamp (ms, performance.now() scale) of the most recent tick() call, or 0 if tick() has never run. Lets a caller tell “frozen on purpose” apart from “stalled” without depending on the frame counter, which doesn’t move either way.

number

attachTicker(subscribe): void

Defined in: GameLoop.ts:84

Attach an external ticker (e.g., PixiJS Ticker). The ticker calls tick(dtMs) every frame with the wall-clock delta in milliseconds. If no ticker is attached, the loop uses requestAnimationFrame.

(callback) => () => void

void


setCallbacks(callbacks): void

Defined in: GameLoop.ts:75

Provide the callbacks that the loop invokes each frame.

GameLoopCallbacks

void


start(): void

Defined in: GameLoop.ts:91

Start the loop.

void


stop(): void

Defined in: GameLoop.ts:112

Stop the loop.

void


tick(dtMs): void

Defined in: GameLoop.ts:135

Process one frame. dtMs is the wall-clock delta in milliseconds (the unit PixiJS tickers report). It is converted to seconds here, so every callback receives seconds.

A throw that escapes the whole frame — nothing downstream caught it — stops the loop and rethrows, so it reaches the host (a caller’s own try/catch, window.onerror, or an unhandled-rejection handler). An error handled inside the frame (a caller’s try/catch around, say, entity.emit(...)) never reaches here, so the loop keeps running.

number

void