Docs · Connecting and game lifecycle

SDK

Connecting and game lifecycle

Connect once, then tell VPlay when the game is loading, playing and finished.

Connecting

VPlay.init({ gameId }) asks VPlay for the player, prices and save. It resolves with:

init result
{
  mode: "vplay" | "standalone",
  player: { signedIn, displayName, member },
  vcoins: number,            // display only, never use it for game logic
  items: [{ id, label, priceVc, owned }],
  entitlements: string[],    // item ids this player owns
  save: any | null,          // cloud save
  capabilities: string[],    // what we switched on for your game
  sdkVersion: 1,
  host: { revision, features, limits, theme, locale, scoreOrder, tournament } | null
}

Your game trusts messages only from VPlay (and any hostOrigins you pass while testing). If the page that frames your game does not answer, the SDK falls back to standalone: after 12 seconds with no sign of a host, or after up to 45 seconds if a host is there but its server is slow. A temporary server error is retried for you.

  • gameId: the id we register for your game.
  • hostOrigins: extra host addresses to trust while testing a local build. Remove them before launch.
  • openUrl: where openOnVplay() sends a standalone player.
  • autoTheme: mirror VPlay's colours into CSS variables (default on).

Lifecycle

JavaScript
VPlay.loading(0.4);              // assets loading
VPlay.loading(1);                // ready

VPlay.gameplayStart();           // a run starts: the player is driving
VPlay.gameplayStop();            // a menu, pause screen or shop is up
VPlay.gameplayStart();           // back in the action

const run = await VPlay.gameOver({ score: 4200, level: 3 });
// run -> { accepted, flagged, best }
  • loading(progress): 0 to 1 while assets load.
  • gameplayStart() / gameplayStop(): when the player is actually playing (a run opens on our server), and when a menu, pause or shop is up.
  • gameOver() / win(): a finished run. The server decides; a flagged run is never ranked or rewarded.
  • After a finished run, call gameplayStart() again when the next one begins so it is timed from the start.