Skip to main content
πŸŽ‰ GP CONF 2026: WEB Games Market Conference πŸ‘Ύ September 23 | Details

Multiplayer

Concept​

  • The Multiplayer module synchronizes a real-time game between players in the same GamePush channel.
  • A channel acts as a room. All players connected with the same channelId join the same multiplayer session.
  • A player must be a channel member before connecting to multiplayer.
  • The SDK automatically selects the host and migrates the role when the current host disconnects.
  • Player state, shared world state, and one-time game events are synchronized separately.
  • The SDK buffers and interpolates state updates automatically.
  • Two synchronization modes are available: fast for lower latency and smooth for more stable movement.

Host and Peers​

Multiplayer uses a host/peer model:

  • Host receives player updates, keeps the authoritative state, and sends snapshots to the other players.
  • Peers send their own player state to the host and receive the synchronized state of the room.

SDK selects the host automatically and migrates the role if the current host disconnects or another player becomes a better candidate.

Host selection considers connection stability, time spent in the room, and ping. Do not assign a permanent host in the game code. Check gp.multiplayer.isHost and react to the becameHost and becamePeer events instead.

info

Host selection happens after connecting and may take a few seconds. Do not assume that gp.multiplayer.isHost has its final value immediately after connect() resolves.

Choose the Right Synchronization Mechanism​

Multiplayer provides three mechanisms for different kinds of data:

MechanismUse it forExamples
Player stateState controlled by an individual playerPosition, direction, animation, health
Global stateShared entities and rules controlled only by the hostEnemies, items, round timer, shared score
MessagesOne-time actions that do not need to be stored as stateShot, explosion, emote, button press

Do not send continuously changing coordinates as messages. Use player or global state so the SDK can buffer and interpolate them.

Synchronization Modes​

The mode configures the tick rate and interpolation buffer for both player and global state.

Fast​

gp.multiplayer.setMode('fast');
  • 60 ticks per second;
  • 50–100 ms interpolation buffer;
  • lower latency and higher network traffic;
  • suitable for action games, shooters, and racing games.

Smooth​

gp.multiplayer.setMode('smooth');
  • 20 ticks per second;
  • 100–300 ms interpolation buffer;
  • smoother behavior on unstable connections and lower network traffic;
  • suitable for strategies, board games, and slower real-time games.

The default SDK configuration corresponds to smooth.

Choose the mode before starting the game loop. The mode can be changed while connected, but doing so restarts the SDK tick and state-sending loops.

State Schemas​

Player and global state use schemas with the same field options:

{
x: { interpolate: true },
hp: { interpolate: false },
color: { readonly: true },
}
  • interpolate: true smoothly transitions numeric values between received snapshots.
  • interpolate: false applies the latest value without interpolation.
  • readonly: true marks initial metadata that should not be changed by subsequent state updates.

Schemas can contain nested objects and arrays of objects:

gp.multiplayer.defineGlobalSchema({
enemies: {
id: { readonly: true },
x: { interpolate: true },
y: { interpolate: true },
hp: { interpolate: false },
},
});

The SDK maintains a jitter buffer and automatically interpolates or briefly extrapolates synchronized numeric fields. Game code reads the resulting state without implementing its own network interpolation.

Game Logic and Rendering​

Use onTick() for game logic and requestAnimationFrame() for rendering:

function gameTick(delta) {
updateGame(delta);
}

function render() {
drawGame();
requestAnimationFrame(render);
}

gp.multiplayer.onTick(gameTick);
requestAnimationFrame(render);

The SDK tick loop continues working when a browser tab is in the background. Rendering can remain tied to requestAnimationFrame().

Getting Started​

  • Create or choose a channel for the game room.
  • Add all players to the channel.
  • Subscribe to multiplayer events and connect using the channel ID.
  • Define player and global state schemas.
  • Choose a synchronization mode and start the game loop.

Go to the detailed multiplayer documentation πŸ‘‡

Stay in Touch​

Other documents of this chapter are available here. To get started with GamePush, see the Tutorials chapter.

GamePush Community Telegram: @gs_community.

For your suggestions e-mail: official@gamepush.com

We Wish you Success!