Replay: speed property

Available since @irtio/client 5.0BrowsersNode

The speed property of the Replay interface is how fast play() runs, as a multiple of the room’s tick rate.

Value

A number greater than 0. Defaults to 1, the room’s own speed.

Description

play() shows one tick every 1000 / (tickRate * speed) milliseconds, so a speed of 2 plays a 20-tick-a-second room at 40 ticks a second, and 0.25 in slow motion. Every tick is shown at any speed, with its events. A change takes effect from the next tick played.

Examples

Offering playback speeds

A replay viewer’s speed menu sets the speed from its options.

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

export function bindSpeedMenu(replay: Replay, menu: HTMLSelectElement): void {
  for (const speed of [0.25, 0.5, 1, 2, 4]) menu.add(new Option(`${speed}x`, String(speed), false, speed === replay.speed));
  menu.addEventListener("change", () => (replay.speed = Number(menu.value)));
}

See also

Runtime availability

BrowsersNode
speed5.05.0