How to make a Phaser game multiplayer
Updated 2026-11-08
Tested on 8 November 2026 with Phaser 3.90.0 (two players, a full round and a rematch, on staging and keyless localhost).
Short answer: load Joinable's script, then register your game with Joinable.game() from your main scene. Joinable runs the waiting room, the 3-2-1, live standings, results and rematch; your scene starts a round from a shared seed, reports its player, and draws the others as sprites. No server, no Socket.IO. We built a small Phaser 3.90 race this way and it took about 20 minutes, self-test included.
Which pattern fits your Phaser game
| Your game | Use |
|---|---|
| Racer, runner, anything with a finish line | Full rounds, race |
| Arcade, puzzle, shooter-vs-the-clock: anything with a score | Full rounds, score |
| Board or card game whose rules live in a plain object | Pattern A |
| Platformer or top-down with an avatar per player | Pattern B |
| RTS, tower defence, auto-battler | Lockstep (see the end of this page) |
Phaser's game objects (sprites, bodies, scenes) are class instances that point at each other, so never sync them: a sprite leads into the whole scene graph, and the diff hits Joinable's message limits or syncs garbage. Full rounds don't need to: you report a few numbers and draw the rest. For Pattern A, keep the rules in a plain object (this.state = { board, turn, scores }) that the scene draws from, and sync that. Engine-side fields go under keys starting with _. Pattern A's guest-side prediction relies on the same requestAnimationFrame wrapper, so on an engine that owns its loop, test Pattern A with two windows before relying on it.
Full rounds in a Phaser scene
<script src="https://cdn.jsdelivr.net/npm/phaser@3.90.0/dist/phaser.min.js"></script>
<script src="game.js"></script>
<script async src="https://relay.getjoinable.com/sdk.js" data-connect="invite"></script>
No key while you build. On localhost Joinable works without one, free, in rooms of up to 4 players. Before the game goes live on a real site, get a key free at getjoinable.com/app and add data-key="pk_…" to the tag. Set theme to your game's own colours and font too: Joinable's waiting room, countdown and results then look like part of your game (the kit's "Match the game's look").
class Race extends Phaser.Scene {
constructor() { super('Race'); }
create(data) {
// data.seed comes from Joinable when online; solo play picks its own.
this.rnd = new Phaser.Math.RandomDataGenerator([String(data.seed ?? Date.now())]);
this.buildTrack(this.rnd); // course and spawns from the seeded generator only
const slot = data.slot ?? 0; // your place on the grid, so cars don't start on top of each other
this.car = this.physics.add.sprite(100, 200 + slot * 50, 'car');
this.rivals = new Map(); // player id → sprite
this.others = []; // filled by Joinable's remote() hook, below
this.frozen = !!data.online; // online: wait for go()
}
update(time, delta) {
if (!this.frozen) this.driveCar(delta);
// Draw the other players where Joinable says they are now.
for (const p of this.others) {
if (!p.state) continue; // no position from them yet (the first moments of a round)
let s = this.rivals.get(p.id);
if (!s) this.rivals.set(p.id, (s = this.add.sprite(0, 0, 'car').setTint(Phaser.Display.Color.HexStringToColor(p.color).color)));
s.setPosition(p.state.x, p.state.y).setRotation(p.state.a).setAlpha(p.stale ? 0.3 : p.contact ? 1 : 0.5);
}
}
}
const game = new Phaser.Game({ type: Phaser.AUTO, width: 960, height: 540, physics: { default: 'arcade' }, scene: [Menu, Race] });
// Menu and Race are your scenes, each with a key: super('Menu'), super('Race').
(window.JoinableQ = window.JoinableQ || []).push((Joinable) => {
game.registry.set('online', true); // let the menu show its "Play online" button
Joinable.game({
profile: 'race',
name: 'My Racer',
players: { min: 2, max: 8 },
theme: { accent: '…', panel: '…', text: '…', font: '…' }, // your game's own colours and font
public: true,
start({ seed, players, me }) {
const slot = players.findIndex((p) => p.id === me);
game.scene.stop('Menu');
game.scene.start('Race', { seed, slot, online: true }); // restarts the scene on a rematch too
},
go() { game.scene.getScene('Race').frozen = false; },
local() {
const s = game.scene.getScene('Race');
if (!s?.car) return null; // not racing yet
const c = s.car, v = c.body.velocity;
return { x: c.x, y: c.y, a: c.rotation, vx: v.x, vy: v.y, lap: s.lap, progress: s.progress };
},
// Every frame (Phaser runs on requestAnimationFrame, so this fires before each update()).
remote(players) { const s = game.scene.getScene('Race'); if (s) s.others = players; },
stop() { game.scene.stop('Race'); game.scene.start('Menu'); },
});
});
// In the scene, when the player crosses the line for the last time:
window.Joinable?.finish({ time: this.elapsed / 1000 });
In the menu scene, a "Play online" button calls window.Joinable?.open(). Joinable loads async, so it can arrive after the menu is drawn: show the button from the registry, and listen for the change.
class Menu extends Phaser.Scene {
constructor() { super('Menu'); }
create() {
this.add.text(480, 290, 'Play solo', { fontSize: '32px' }).setOrigin(0.5)
.setInteractive().on('pointerdown', () => this.scene.start('Race', {}));
const online = this.add.text(480, 370, 'Play online', { fontSize: '32px' }).setOrigin(0.5)
.setInteractive().on('pointerdown', () => window.Joinable?.open())
.setVisible(!!this.registry.get('online'));
this.registry.events.on('changedata-online', (_parent, on) => online.setVisible(!!on), this);
this.events.once('shutdown', () => this.registry.events.off('changedata-online', undefined, this));
}
}
Notes:
remote(players)works in Phaser: Phaser's loop runs onrequestAnimationFrame, and Joinable calls the hook before each frame. Store the list on the scene and draw it inupdate, as above. ReadingJoinable.remote()insideupdateworks too (getjoinable 0.2.3 and later accept either; 0.2.2 fails a game that has noremotehook).- A rival's
stateisnulluntil their first update arrives. Skip them until then, orp.state.xthrows. - Typing in Joinable's screens is safe. Phaser's
createCursorKeys()captures the arrow keys and Space, but a name typed into Joinable's waiting room still arrives (checked with Phaser 3.90, with a race scene running). - Names: pass
me: { name }inJoinable.gameif your game knows the player's name. Otherwise players get a made-up one and can set their own in the waiting room. - Bumping: with Arcade physics, treat each rival as a static body at
p.stateand, on overlap, push only your own car by half the overlap, scaled byp.contact. The kit's "Drawing other players and bumping" section has the rules. - Score games: use
profile: 'score',local() { return { score } }, andJoinable.finish({ score }). Noremoteneeded: Joinable shows live scores itself.
Test it
Serve the folder (npx serve -l 8080, or python3 -m http.server 8080), then:
npx getjoinable test http://localhost:8080/
It plays a round with two headless players and checks seed, local, remote, results and rematch. If your race doesn't finish on its own within 60 seconds, the test finishes it and says so: that's fine. Then play one real round in two browser windows side by side (Play online, Invite, open the link in the other window, Ready in both), and once more on a phone and a laptop.
Where this stops working
- Arcade and Matter physics aren't deterministic across devices, so rivals are predicted, not simulated. Fine for racing and party games; not for physics puzzles where every player must see the same pile of boxes fall the same way.
- Strategy games and big simulations need the
lockstepprofile: the simulation runs outside Phaser'supdate(), one fixed tick at a time, and not on Arcade physics, whose timing follows the frame rate. The kit's "Lockstep" chapter has the rules; the self-test checks the result.