The GameRoom template — add a multiplayer room
GameRoom is the generic multiplayer room the template ships as a starting point — a small
arena with players and collectible orbs. The shipped arena example uses its own room
(arena_room), but GameRoom is the one you copy when adding multiplayer to your own game. This is
a terminal tour of it (real captured output below).
# transcript pending capture — run: node site/media/capture-cli.mjs site/media/capture-cli.mjs -
The room is its Schema state.
game-room.tsdefinesPlayerSchema(sessionId, name, color, x/y/z, score),OrbSchema(id, x, z), andGameState(maps of players + orbs). With@colyseus/schema, the server mutates state directly and Colyseus delta-encodes and syncs it to every client — new joiners get the full state automatically. Clients only send apositionmessage (onMessage); everything else is server-authoritative state.onJoin/onLeaveadd and remove players. -
Register it, then opt in.
rooms.tsregisters two rooms —{ name: 'game_room', handler: GameRoom }and{ name: 'arena_room', handler: ArenaRoom }. An example points at a room by declaring"server": {"room": "..."}in its folder’svgai.game.json(the shippedthird-person-arenaexample usesarena_room); set"room": "game_room"to use this one.
Recap
New functionality
- Read the GameRoom Schema state (players + orbs)
- Saw the room registered and how an example opts in
New concepts & skills
- a Colyseus room IS its @colyseus/schema state — server mutates, deltas sync automatically
- clients send minimal input (position); the server is authoritative
- rooms.ts maps a name → handler; an example selects it via its manifest's server.room
Next lesson → Colyseus rooms (reference)