Phaser 3

The Gamealia Phaser plugin is a Phaser 3 global plugin over the JavaScript SDK. It calls init() at boot, loadingStop() when your loading scene is ready and gameplayStart() / gameplayStop() when your play scenes start, pause or stop, and it pauses and mutes the game while the portal pauses it or an ad plays. Everything else is the JavaScript SDK, one property away. Tested with Phaser 3.90.

Install

  1. Load the SDK and the plugin in index.html, before your game's script:

    <script src="https://gamealia.app/sdk/v1.js"></script>
    <script src="https://gamealia.app/sdk/phaser-plugin.js"></script>

    The plugin is window.GamealiaPlugin. It works with Phaser from a script tag or from npm (Vite, webpack), whichever loads first.

  2. Add it to the game config as a global plugin:

    new Phaser.Game({
      // ...your config
      scene: [Boot, Menu, Game],
      plugins: {
        global: [
          {
            key: "Gamealia",
            plugin: window.GamealiaPlugin,
            start: true,
            data: { loadingScene: "Boot", gameplayScenes: ["Game"] },
          },
        ],
      },
    });
  3. Build and upload the output folder (dist/ with Vite), with index.html at its root.

Starting a new game? gamealia new my-game --template phaser creates a Vite project that already uses the plugin.

Options

The plugin's data:

OptionDefaultWhat it does
loadingScenenoneKey of the scene that loads your assets. loadingStop() runs after its preload() finished and its create() ran. Without it, after the first scene's create()
gameplayScenesevery scene except loadingSceneKeys of the scenes where the player is playing. gameplayStart() when one is created, resumed or woken; gameplayStop() when the last one pauses, sleeps or shuts down. []: you call them yourself
autoLoadingStoptruefalse: call loadingStop() yourself
autoPausetruePause the running scenes and sounds while the portal pauses the game or an ad plays
autoMutetrueSet game.sound.mute while the portal is muted or an ad plays (your own mute setting comes back after)

Menus that live in their own scene stay out of gameplayScenes, so time in menus does not count as play.

Use

class Game extends Phaser.Scene {
  async create() {
    const gml = this.plugins.get("Gamealia");
    const info = await gml.ready; // init() result: locale, device, joinRoom...
    this.title = this.add.text(20, 20, TEXTS[gml.locale]?.title ?? TEXTS.en.title);
    gml.on("localeChange", () => this.title.setText(TEXTS[gml.locale]?.title ?? TEXTS.en.title));
  }

  async levelDone() {
    await this.plugins.get("Gamealia").midgame(); // pauses and mutes while the ad plays
    this.scene.start("Game", { level: this.level + 1 });
  }

  async extraLife() {
    const r = await this.plugins.get("Gamealia").rewarded();
    if (r.rewarded) this.lives++; // only when the player watched the whole ad
  }
}

Show the game in gml.locale (the portal language, one of 32), with English as the fallback, and follow localeChange: the autotest checks both.

API

On the plugin (this.plugins.get("Gamealia")):

MemberWhat it does
readyPromise of the init() result: locale, environment, device, deviceClass, country, app, user, joinRoom, joinKey, joinParams, instantMultiplayer, chatOff, os, browser
whenReady(cb)Calls cb(info) once the SDK is ready
localeThe portal language; follows localeChange
midgame()Midgame ad at a natural break; resolves with { shown, rewarded, reason? }
rewarded()Rewarded ad; give the reward only when rewarded is true
gameplayStart() / gameplayStop()Play started or stopped inside a scene (a game over screen or a pause menu over the play scene)
loadingStop()Only with autoLoadingStop: false
on(event, cb)SDK events: localeChange, pause, resume, mute, unmute, adStart, adEnd, userChange, roomJoin, friendsChange. Returns the unsubscribe function
sdkThe JavaScript SDK (window.Gamealia) for everything else

Through sdk, the same calls as in plain JavaScript (see the SDK reference):

AreaCalls
Gamesdk.game.happyTime(), sdk.game.setProgress(p), sdk.game.setContext(c), sdk.game.reportError(m), sdk.game.track(category, what, action)
Adssdk.ad.hasAdblock(), sdk.ad.requestBanner({ id, size, anchor, position }) or with a container, sdk.ad.requestResponsiveBanner(id), sdk.ad.clearBanner(id), sdk.ad.clearAllBanners() (in-game banners drawn by the portal; they show once ads are live on Gamealia)
Playersdk.user.get(), sdk.user.getToken(), sdk.user.requestLogin(), sdk.user.onChange(cb) (Player accounts)
Cloud savesdk.data.load(), sdk.data.get(key), sdk.data.set(key, value), sdk.data.remove(key), sdk.data.clear() (Cloud save)
Rooms and friendssdk.room.*, sdk.presence.setStatus(text), sdk.friends.list(), sdk.friends.invite(id, code), sdk.friends.onChange(cb) (Multiplayer)
Leaderboardssdk.leaderboard.submit(board, value), sdk.leaderboard.get(board, options), sdk.leaderboard.show(board) (Leaderboards)
Chat, storesdk.chat.*, sdk.store.*

A game over screen inside the play scene: call gml.gameplayStop() when it shows and gml.gameplayStart() on "play again" (restarting the scene with this.scene.restart() starts play again on its own).

Audio and pause

With the defaults you do not handle pause, mute or ads yourself: the plugin pauses the scenes that were running (scenes you paused stay paused), pauses and resumes game.sound, and sets game.sound.mute. Audio that does not go through Phaser's sound manager (a separate Howler or <audio> element) still needs gml.on("mute", ...) and gml.on("unmute", ...).

Without the script tag

If the page has no SDK script tag, the plugin loads https://gamealia.app/sdk/v1.js itself and warns in the console. Keep the tag anyway: the autotest looks for it, and the game starts sooner.

Already use another portal's Phaser plugin?

You can keep that code: load our compatibility shim instead of that portal's SDK, as the migration guides explain. For new work, the Gamealia plugin above gives you the player's language, cloud save, rooms and friends.

Common autotest failures

  • loading_stop: no loadingScene, and no scene is ever created (the game waits for a click before new Phaser.Game). Create the game at once, or call gml.loadingStop().
  • gameplay_start / gameplay_stop: gameplayScenes: [] without calling the plugin's gameplayStart() / gameplayStop().
  • sdk_loaded: phaser-plugin.js is loaded, v1.js is not. Add both tags.
  • translations: text drawn with gml.locale once, without on("localeChange").

Problems or questions: the Support chat in your dashboard, or hello@gamealia.app (Support).