Replay: entities property
Available since
@irtio/client 5.0BrowsersNodeThe entities read-only property of the Replay interface holds the replay’s entities at the tick shown, with the same events as a live room’s.
Value
An EntityStore.
Description
A replay records every entity a client that sees everything would have seen. Its store’s callbacks fire as a live client’s do: play() and step() fire each tick’s leaves, enters and changes, and seek() makes the entities shown leave and those at the new tick enter, without the changes between. So the code that renders a live room renders a replay when given this store instead of room.entities.
The entities are read-only.
Examples
Rendering a replay with the live game’s code
A game’s renderer takes an EntityStore, so the live game passes room.entities and the replay viewer passes replay.entities.
// render-goals.ts
import { defineSchema, entity, type EntityStore } from "@irtio/client";
import { loadReplay } from "@irtio/client/replay";
const Ball = entity("ball", { x: "f32", y: "f32" });
export const schema = defineSchema({ entities: [Ball] });
export function renderBalls(entities: EntityStore): void {
entities.onEnter(Ball, (b) => console.log(`ball ${b.id} appears`));
entities.onChange(Ball, (b) => console.log(`ball ${b.id} at ${b.x}, ${b.y}`));
entities.onLeave(Ball, (b) => console.log(`ball ${b.id} gone`));
}
export function watch(bytes: Uint8Array): void {
const replay = loadReplay(bytes, { schema });
renderBalls(replay.entities);
replay.play();
}
See also
EntityStoreReplay.state- Playing back in Replays and clips
Runtime availability
| Browsers | Node | |
|---|---|---|
entities | 5.0 | 5.0 |