WorldUpdate
world/world-update.ts:54The per-tick context produced by World.update and threaded into
every component's onPreUpdate, onUpdate, and onPostUpdate hook for
the duration of that tick.
WorldUpdate is the canonical place to read timing information during
behavior code:
- WorldUpdate.deltaMilliseconds / WorldUpdate.deltaSeconds — the wall-clock time since the previous tick, in either unit. Multiply by per-tick rates to make movement frame-rate-independent.
- WorldUpdate.elapsedMilliseconds / WorldUpdate.elapsedSeconds — the total time since the world's first tick. Useful for animation curves, lifetimes, or anything driven by absolute time rather than per-frame delta.
- WorldUpdate.frameIndex — a monotonic tick counter starting at
0for the world's first tick. Unlocks "every N frames" patterns, reproducible debug stops, and deterministic phase offsets.
Both unit pairs are derived from the same underlying measurement; pick
whichever reads best at the call site. The seconds-based variants are the
conventional unit for game-physics math
(velocity * update.deltaSeconds); the millisecond-based variants match
arcade2d's WorldTimer unit so timer ticks compose without
conversion.
First-tick behavior
On the world's very first tick there is no prior timestamp to diff
against, so deltaMilliseconds (and therefore deltaSeconds) is
deliberately 0. This prevents the inaugural tick from emitting a
gigantic delta that would teleport every moving entity. Behavior code can
rely on update.deltaMilliseconds === 0 meaning "no time advanced" and
skip work accordingly.
Example
onUpdate(update: WorldUpdate): void {
// seconds-based: idiomatic for physics
this.host.position.x += this._velocity * update.deltaSeconds;
// milliseconds-based: pairs with WorldTimer
if (this._cooldown.decrement(update.deltaMilliseconds).isLapsed) {
this.fire();
}
// frame-stride pattern
if (update.frameIndex % 30 === 0) {
this.sampleEnvironment();
}
}Constructors
constructor(deltaMilliseconds: number, elapsedMilliseconds: number, frameIndex: number): WorldUpdate Parameters
-
deltaMillisecondsnumber -
elapsedMillisecondsnumber -
frameIndexnumber
Properties
deltaMilliseconds: number The time since the previous tick, in milliseconds. Always 0 on the
world's first tick. Always non-negative.
elapsedMilliseconds: number The total time since the world's first tick, in milliseconds. 0 on
the very first tick, then accumulates monotonically.
frameIndex: number A monotonic tick counter. 0 on the world's first tick, incrementing
by 1 on every subsequent World.update call.
Accessors
deltaSeconds: number The time since the previous tick, in seconds. Convenience accessor
equal to deltaMilliseconds / 1000. The idiomatic unit for
per-second-rate game math (velocity * deltaSeconds).
elapsedSeconds: number The total time since the world's first tick, in seconds. Convenience
accessor equal to elapsedMilliseconds / 1000.