arcade2d
Class

WorldUpdate

world/world-update.ts:54

The 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:

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

  • deltaMilliseconds number
  • elapsedMilliseconds number
  • frameIndex number

Properties

readonly #
deltaMilliseconds: number

The time since the previous tick, in milliseconds. Always 0 on the world's first tick. Always non-negative.

readonly #
elapsedMilliseconds: number

The total time since the world's first tick, in milliseconds. 0 on the very first tick, then accumulates monotonically.

readonly #
frameIndex: number

A monotonic tick counter. 0 on the world's first tick, incrementing by 1 on every subsequent World.update call.

Accessors

readonly #
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).

readonly #
elapsedSeconds: number

The total time since the world's first tick, in seconds. Convenience accessor equal to elapsedMilliseconds / 1000.

ESC