Replay: tick event

Available since @irtio/client 5.0BrowsersNode

The tick event of the Replay interface fires when the replay shows a tick: by play() or step() moving to it, or by seek().

Syntax

addEventListener("tick", (event) => {})

Event type

A generic Event. Read the tick shown from the replay’s tick property.

Description

The event fires after the tick’s entity and presence callbacks, so the replay’s entities, state and presence are those of the tick by then. Use it for what depends on the whole tick rather than one entity, such as a clock or a scoreboard.

Examples

Showing a match clock

A replay viewer shows the match clock, counting from the replay’s first tick.

// match-clock.ts
import type { Replay } from "@irtio/client/replay";

export function matchClock(replay: Replay, label: HTMLElement): void {
  replay.addEventListener("tick", () => {
    const seconds = (replay.tick - replay.firstTick) / replay.tickRate;
    label.textContent = `${seconds.toFixed(1)} s`;
  });
}

See also

Runtime availability

BrowsersNode
tick event5.05.0