Search documentation

Find pages, sections, and content across all docs.

WavedashDocs

Phaser

Build a Phaser 4 game with your bundler of choice and ship it to Wavedash.

View example project on GitHub Playtest the example project

Phaser works with any JavaScript bundler — Vite, Webpack, Rollup, esbuild, Parcel, and others. This page covers the generic setup. The example repo uses Vite.

Install dependencies

npm install @wvdsh/sdk-js

The default export is the live, fully-typed Wavedash SDK singleton.

Wire up Wavedash.init()

Call Wavedash.init() when your Preloader scene finishes loading. Don't use Phaser's postBoot callback: it fires as soon as the game boots, before any scene has loaded assets, so the loading screen would disappear too early.

Calling Wavedash.init() is required. Your game stays hidden behind the Wavedash loading screen until you do. Call it once your game is ready to play.

import { AUTO, Game } from "phaser";

const config: Phaser.Types.Core.GameConfig = {
  type: AUTO,
  width: 1024,
  height: 768,
  parent: "game-container",
  scene: [Boot, Preloader, MainMenu, MainGame, GameOver],
};

const StartGame = (parent: string) => new Game({ ...config, parent });

export default StartGame;

Methods, events, and payloads all autocomplete. In your Preloader scene, wire Wavedash.updateLoadProgressZeroToOne(...) to Phaser's load progress event and call init() when loading completes:

// src/scenes/Preloader.ts
import Wavedash from "@wvdsh/sdk-js";

export class Preloader extends Phaser.Scene {
  preload() {
    this.load.on('progress', (p: number) => {
      Wavedash.updateLoadProgressZeroToOne(p);
    });
    this.load.once('complete', () => {
      Wavedash.updateLoadProgressZeroToOne(1);
      Wavedash.init({ debug: true });
    });

    // this.load.image(...), this.load.audio(...), etc.
  }
}

init() automatically signals load completion, so call it last. If a scene loads nothing, Phaser fires complete immediately, so the same code works for a game with no assets.

wavedash.toml

Point upload_dir at your bundler's output directory. For Vite and most other bundlers that's ./dist.

game_id = "YOUR_GAME_ID_HERE"
upload_dir = "./dist"

Local development

Produce a build, then run wavedash dev to serve it through the Wavedash sandbox.

SDK features

Once initialized, Wavedash exposes leaderboards, achievements, stats, and user data:

const user = Wavedash.getUser();

const lb = await Wavedash.getLeaderboard("high-scores");
if (lb.success) {
  await Wavedash.uploadLeaderboardScore(lb.data.id, score, true);
}

Wavedash.setAchievement("first_win", true);