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
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.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"] }, }, ], }, });- Build and upload the output folder (
dist/with Vite), withindex.htmlat 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:
| Option | Default | What it does |
|---|---|---|
loadingScene | none | Key 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() |
gameplayScenes | every scene except loadingScene | Keys 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 |
autoLoadingStop | true | false: call loadingStop() yourself |
autoPause | true | Pause the running scenes and sounds while the portal pauses the game or an ad plays |
autoMute | true | Set 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")):
| Member | What it does |
|---|---|
ready | Promise 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 |
locale | The 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 |
sdk | The JavaScript SDK (window.Gamealia) for everything else |
Through sdk, the same calls as in plain JavaScript (see the SDK reference):
| Area | Calls |
|---|---|
| Game | sdk.game.happyTime(), sdk.game.setProgress(p), sdk.game.setContext(c), sdk.game.reportError(m), sdk.game.track(category, what, action) |
| Ads | sdk.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) |
| Player | sdk.user.get(), sdk.user.getToken(), sdk.user.requestLogin(), sdk.user.onChange(cb) (Player accounts) |
| Cloud save | sdk.data.load(), sdk.data.get(key), sdk.data.set(key, value), sdk.data.remove(key), sdk.data.clear() (Cloud save) |
| Rooms and friends | sdk.room.*, sdk.presence.setStatus(text), sdk.friends.list(), sdk.friends.invite(id, code), sdk.friends.onChange(cb) (Multiplayer) |
| Leaderboards | sdk.leaderboard.submit(board, value), sdk.leaderboard.get(board, options), sdk.leaderboard.show(board) (Leaderboards) |
| Chat, store | sdk.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: noloadingScene, and no scene is ever created (the game waits for a click beforenew Phaser.Game). Create the game at once, or callgml.loadingStop().gameplay_start/gameplay_stop:gameplayScenes: []without calling the plugin'sgameplayStart()/gameplayStop().sdk_loaded:phaser-plugin.jsis loaded,v1.jsis not. Add both tags.translations: text drawn withgml.localeonce, withouton("localeChange").
Problems or questions: the Support chat in your dashboard, or hello@gamealia.app (Support).