Retrofit an existing game
You have a working single-player game. The goal is to make it multiplayer without turning your codebase inside out. The trick: model only what’s shared, and leave the rest exactly as it is.
1. Find the shared surface
List the state two players would need to agree on. Usually it’s small — player positions, a score, the current level. Everything else (camera, particles, UI) stays local and untouched.
2. Describe it as a schema
export const schema = defineSchema({
players: map(entity({ x: number(), y: number(), skin: string() })),
score: entity({ red: number(), blue: number() }),
}); 3. Mirror your local writes
Wherever your game already updates that state, also write it to the room. Because owned writes look like plain assignments, this is usually a one-line change:
// before
player.x += dx;
// after
player.x += dx;
room.state.players[room.me].x = player.x; 4. Render remote entities
In your draw loop, add the other players from room state next to your local one:
for (const [id, p] of Object.entries(room.state.players)) {
if (id !== room.me) drawGhost(p);
} 5. Climb only if you need to
Shipped a co-op mode and now want a competitive one? Add validators or a tick loop — no rewrite, just a higher rung.
Next steps
Placeholder guide.