Guide

How to make a PixiJS game multiplayer

Updated 2026-11-08

Short answer: load Joinable's script with async, then register your game with Joinable.game(). Joinable runs the waiting room, the 3-2-1, live standings, results and rematch; your game starts a round from a shared seed, reports its player, and draws the others in its own ticker. No server, no WebSocket code.

Which pattern fits your PixiJS game

Your gameUse
Racer, runner, anything with a finish lineFull rounds, race
Arcade, puzzle, shooter-vs-the-clock: anything with a scoreFull rounds, score
Board or card game whose rules live in a plain objectPattern A
Platformer or top-down with an avatar per playerPattern B
RTS, tower defence, hundreds of unitsLockstep

PixiJS only draws. Its display objects (Sprite, Graphics, Container) point at their parents, textures and the renderer, so never sync them. Keep the game in plain numbers and objects, and let the ticker draw from them. Full rounds need nothing more: you report a few numbers and draw the rest.

For Pattern A, keep the rules in a plain object (const game = { board, turn, scores }) and sync that, with per-device things (keys, mouse, camera) under local. Pattern B adds one step: each player sends their inputs to the host, and the host moves every avatar. The agent kit explains both. PixiJS's ticker runs on requestAnimationFrame, which is what sync follows, but test with two windows side by side before relying on it.

Full rounds in a PixiJS game

<script src="https://cdn.jsdelivr.net/npm/pixi.js@8/dist/pixi.min.js"></script>
<script src="game.js"></script>
<script async src="https://relay.getjoinable.com/sdk.js" data-connect="invite"></script>

On localhost, leave data-key out: local play needs no key, in rooms of up to 4 players. A real site needs the game's key, free at getjoinable.com/app.

// game.js
const app = new PIXI.Application();
let car = null;            // your car: plain numbers, never a Pixi object
let mode = 'menu';         // 'menu' | 'grid' | 'racing' | 'done'
let online = false;
let mine = null;           // the sprite for your car
const rivals = new Map();  // player id → Graphics
let others = [];           // the other players, from Joinable's remote() hook

// A seeded generator: every player builds the same course from the same seed.
function mulberry32(a) {
  return () => {
    a = (a + 0x6d2b79f5) | 0;
    let t = Math.imul(a ^ (a >>> 15), 1 | a);
    t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
    return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
  };
}

const carShape = (color) => new PIXI.Graphics().rect(-14, -8, 28, 16).fill(color);

function newRace(seed, slot) {
  buildTrack(mulberry32(seed));   // course and spawns from the seeded generator only
  car = { x: 120, y: 200 + slot * 40, a: 0, vx: 0, vy: 0, lap: 0, progress: 0, time: 0 };
}

(async () => {
  await app.init({ width: 960, height: 540, background: '#101418' });
  document.body.appendChild(app.canvas);
  mine = app.stage.addChild(carShape('#ffb547'));

  app.ticker.add((ticker) => {
    const dt = ticker.deltaMS / 1000;
    if (mode === 'racing') drive(car, dt);           // your own physics, as before
    if (car) { mine.position.set(car.x, car.y); mine.rotation = car.a; }

    // Draw the other players where Joinable says they are now.
    for (const p of others) {
      if (!p.state) continue;                   // no position from them yet
      let g = rivals.get(p.id);
      if (!g) rivals.set(p.id, (g = app.stage.addChild(carShape('#ffffff'))));
      g.tint = p.color;
      g.position.set(p.state.x, p.state.y);
      g.rotation = p.state.a;
      g.alpha = p.stale ? 0.3 : p.contact ? 1 : 0.5;
    }
    for (const [id, g] of rivals) {
      if (!others.some((p) => p.id === id)) { g.destroy(); rivals.delete(id); }
    }
  });
})();

(window.JoinableQ = window.JoinableQ || []).push((Joinable) => {
  onlineButton.hidden = false;                       // only offer online play once Joinable is here
  onlineButton.onclick = () => Joinable.open();
  Joinable.game({
    profile: 'race',
    name: 'My Racer',
    players: { min: 2, max: 8 },
    public: true,                                    // strangers can find rooms through Quick match
    start({ seed, players, me }) { online = true; newRace(seed, players.findIndex((p) => p.id === me)); mode = 'grid'; },
    go() { mode = 'racing'; },
    local() { return car && { x: car.x, y: car.y, a: car.a, vx: car.vx, vy: car.vy, lap: car.lap, progress: car.progress }; },
    remote(players) { others = players; },           // before every frame
    stop() { online = false; others = []; mode = 'menu'; },
  });
});

// Call this from drive() when the car crosses the line for the last time.
function finishLine() {
  mode = 'done';
  if (online) window.Joinable?.finish({ time: car.time });   // seconds
  else showTime(car.time);                                     // solo, as before
}

onlineButton is a button in your own menu, hidden until Joinable arrives. If Joinable never loads (offline, blocked, slow), the queued setup never runs, the button stays hidden, and the game plays solo as before.

Notes:

Lockstep

For a strategy game with too many units to send, use profile: 'lockstep': only orders travel, and every device runs the same simulation. The rule for PixiJS is the same as above: the renderer only draws, and the units live in plain data that step() updates. The kit's "Lockstep" section lists the six checks a game must pass first, and Tiny Front is a finished example.

Test it

npx getjoinable test http://localhost:8080/

Then one real round on a phone and a laptop.

Where this stops working

Copy the prompt for your coding agent or sign up free