Home/Engines/PixiJS multiplayer

engines · PixiJS

PixiJS multiplayer

PixiJS is the fastest way to draw thousands of sprites. Pair it with the Multiplayer API and those sprites can be other players — up to 128 per room.

Free sandbox · $19.99/mo to go live · cancel anytime

why

An online .io game with PixiJS

.io games need many players in one room and cheap position updates. Both are what the API is designed around: positions travel over the direct channel at zero server cost, and pellets or coins are claimed atomically with setnx so two players can never eat the same one. Our slither-style demo uses this pattern.

code

A complete PixiJS integration

import { Application, Sprite } from 'pixi.js';
import { Multiplayer } from 'https://multiplayerapi.com/sdk/mp.esm.min.js';

const app = new Application();
await app.init({ resizeTo: window, background: '#0c0d10' });
document.body.appendChild(app.canvas);

const mp = new Multiplayer({ key: 'mp_pk_...' });
await mp.login();
const room = await mp.quickmatch({ mode: 'io', max_players: 64 });

const others = new Map();
room.on('peer', (p, from) => {
  let s = others.get(from);
  if (!s) { s = Sprite.from('blob.png'); s.anchor.set(0.5); app.stage.addChild(s); others.set(from, s); }
  s.tx = p.x; s.ty = p.y;
});
room.on('members', (m) => {
  const alive = new Set(m.map((x) => x.account_id));
  for (const [id, s] of others) if (!alive.has(id)) { s.destroy(); others.delete(id); }
});

app.ticker.add(() => {
  for (const s of others.values()) { s.x += (s.tx - s.x) * 0.2; s.y += (s.ty - s.y) * 0.2; }
});
setInterval(() => room.send({ x: me.x, y: me.y }), 60);

// Pellets: first claim wins, no arbiter needed
async function eat(id) {
  room.setnx(`pellets.${id}`, mp.account.id);
  room.inc(`players.${mp.account.id}.score`, 1);
}
room.on('rejected', (r) => { /* someone else got it first: respawn locally */ });
architecture

What goes where

ChannelCallDeliveryUse it for
Directroom.send(data)peer-to-peer, best effort, zero server costpositions, aim, animation
Stateroom.set(path, value)server-validated, kept for the match, reaches late joinershealth, score, whose turn
Eventsroom.emitEvent(topic, data)ordered, guaranteed, not persistedchat, rematch, one-shots
  • Declare "players.$self.score": {"write":"self","type":"int","monotonic":"up","delta_max":1} so a client cannot jump its score.
  • Submit the final score with mp.submitScore('arena', score) for daily, weekly and all-time leaderboards.
Questions
How many players fit in one PixiJS .io room?

Up to 128 per room. Positions are peer-to-peer where possible; the relay cadence widens automatically as rooms grow to keep cost stable.

Do I need to write server code for leaderboards?

No. Leaderboards with daily, weekly, monthly and all-time windows are built in: mp.submitScore() and mp.leaderboard().

Make your game online today

Free sandbox keys in one call, no account and no card. $19.99/month when you ship, for every game you make.

Free sandbox · $19.99/mo to go live · cancel anytime