Replay: seek() method
Available since
@irtio/client 5.0BrowsersNodeThe seek() method of the Replay interface shows the state at a tick.
Syntax
seek(tick)
Parameters
tick- A number: the room tick to show. It’s rounded down, and clamped to the range from
firstTicktolastTick.
Return value
None (undefined).
Exceptions
None.
Description
A seek starts from the full state at or before the tick and applies the ticks after it, so it’s fast anywhere in a replay. The entities shown before leave and those at the tick enter, without the changes between, and players leave and join presence the same way. Then the tick event fires. Recorded messages between the two ticks are skipped: a message event fires only while playing through its tick.
A replay that’s playing carries on playing from the new tick.
Examples
Jumping to each goal
A match’s goals are known by tick, so the viewer’s buttons seek a few seconds before each one.
// goals.ts
import type { Replay } from "@irtio/client/replay";
export function goalButtons(replay: Replay, goals: number[]): HTMLButtonElement[] {
return goals.map((tick, i) => {
const button = document.createElement("button");
button.textContent = `Goal ${i + 1}`;
button.addEventListener("click", () => replay.seek(tick - 3 * replay.tickRate));
return button;
});
}
seek() clamps a tick before the first, so a goal in the first seconds starts at the beginning.
See also
Replay.step()Replay.firstTick- Playing back in Replays and clips
Runtime availability
| Browsers | Node | |
|---|---|---|
seek() | 5.0 | 5.0 |