Guide

How to make a canvas game multiplayer

Updated 2026-11-08

Short answer: for a game whose rules change one global state object from click or key handlers, add one script tag with data-sync="game". For racers and score games, add the script tag and one Joinable.game() call. Joinable's hosted relay does the rest: invites, quick match, the waiting room, countdown, results and rematch.

Plain canvas games are where Joinable does the most for the least: every pattern works, and three of our demos are canvas games you can read.

Shared world: one line

If your game keeps its world in a top-level game (or state, world) in a classic script, and your input handlers change it:

   <canvas id="game" width="800" height="600"></canvas>
   <script src="game.js"></script>
+  <script src="https://relay.getjoinable.com/sdk.js" data-sync="game" data-local="keys,mouse"></script>

That's the whole change in the Bubble Pop demo (compare the original). Give array items an id, keep per-device things (pressed keys, mouse, camera) under the data-local keys, and read "Where this stops working".

If the state lives in a module or a class, call Joinable.sync(game, { local: ['keys', 'mouse'] }) once it exists, instead of data-sync.

Full rounds: racers and score games

<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").

(window.JoinableQ = window.JoinableQ || []).push((Joinable) => {
  onlineButton.hidden = false;
  onlineButton.onclick = () => Joinable.open();
  Joinable.game({
    profile: 'race',
    name: 'Kart Loop',
    players: { min: 2, max: 8 },
    theme: { accent: '…', panel: '…', text: '…', font: '…' }, // your game's own colours and font
    public: true,
    start({ seed, options, players, me }) { 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) { rivals = players; },          // draw each at p.state in your own loop
    stop() { mode = 'menu'; rivals = []; },
  });
});

window.Joinable?.finish({ time });                   // at the line

The complete, commented version is Kart Loop's source: search for JOINABLE. A score game is shorter still: Bubble Pop, score attack.

Avatars

A game where each player moves a character with held keys needs Pattern B: inputs go to the host, the host moves everyone. Star Catcher shows it; the changes are marked MP: in multi.js, and the agent kit explains each step.

Test it

npx getjoinable test http://localhost:8080/

For shared-world games, open the game in two windows side by side (not two tabs: browsers throttle background tabs) and check both show the same world.

Where this stops working

Copy the prompt for your coding agent or sign up free