Cocos Creator 3.x
Verified with a real Cocos Creator 3.4.2 web-mobile build. The Gamealia package, added to that build, passes the autotest's SDK checks (init, loading, gameplay start/stop, language). Not verified yet: a build made by the Cocos Creator editor with the package installed, and Cocos Creator 3.6 or newer. If something does not work, tell us in the Support chat in your dashboard or at hello@gamealia.app: include your Cocos Creator version, the build platform (Web Mobile or Web Desktop) and what you expected to happen.
The Gamealia package is two TypeScript files for Cocos Creator 3.x: Gamealia.ts, a typed, promise-based layer over the JavaScript SDK (it loads the SDK itself, so no build template is needed), and GamealiaBootstrap, a component that starts the SDK, calls loadingStop(), pauses the game loop and mutes every AudioSource while the portal asks it to.
Install
- Run
gamealia initin your Cocos project folder (or let your AI assistant run it through the MCP server): it copies the package toassets/gamealia/. Or download gamealia-cocos.zip and unzip it into the project folder (it containsassets/gamealia/). Cocos Creator imports the files and writes their.meta. - In your first scene, add an empty node at the scene root (for example "Gamealia") and add the GamealiaBootstrap component to it. The node is kept across scenes.
Minimal flow
import { _decorator, Component } from "cc";
import { Gamealia } from "./gamealia/Gamealia"; // path relative to this script
const { ccclass } = _decorator;
@ccclass("Game")
export class Game extends Component {
async start() {
const info = await Gamealia.init(); // same result GamealiaBootstrap got
this.setLanguage(info.locale); // "en", "es", "pt-BR", ...: use your closest language
Gamealia.events.on("localeChange", (locale: string) => this.setLanguage(locale));
Gamealia.game.gameplayStart();
}
async onLevelEnd() {
Gamealia.game.gameplayStop();
await Gamealia.ad.requestMidgame(); // the game is paused and muted while the ad plays
Gamealia.game.gameplayStart();
}
async onWatchAdForCoins() {
Gamealia.game.gameplayStop();
const ad = await Gamealia.ad.requestRewarded();
if (ad.rewarded) this.coins += 10; // only when rewarded is true
Gamealia.game.gameplayStart();
}
setLanguage(locale: string) { /* ... */ }
coins = 0;
}
Off the portal (editor preview, your own server) the SDK runs in mock mode: ads are simulated and saves stay in the browser, so the game keeps working.
GamealiaBootstrap properties
| Property | Default | What it does |
|---|---|---|
| Manual Loading Stop | off | On: call Gamealia.game.loadingStop() yourself once the game is playable. |
| Mute Audio | on | Sets every AudioSource volume to 0 while the portal mutes the game (ads, the player's mute button) and restores it after; scenes loaded while muted start silent. |
| Pause Game | on | game.pause() while the portal pauses the game, game.resume() after. |
Audio you play some other way (your own WebAudio, a video element): listen to Gamealia.events.on("mute") and on("unmute") and silence it yourself.
Calls and events
Every call returns a promise (or nothing for fire-and-forget calls) and has the same name as in the SDK reference:
| Area | Calls |
|---|---|
| Start | Gamealia.init() → { environment, locale, gameId, user, device, deviceClass, country, app, joinRoom, joinKey, joinParams, instantMultiplayer, chatOff, os, browser } |
| Game | game.loadingStart(), game.loadingStop(), game.gameplayStart(), game.gameplayStop(), game.happyTime(), game.setProgress(percent), game.setContext({ level: 3 }), game.reportError(error), game.track(category, what, action?) |
| Ads | ad.requestMidgame(), ad.requestRewarded() → { shown, rewarded, reason }, ad.hasAdblock(), ad.requestBanner(id, size, anchorX, anchorY, posX, posY) and ad.requestResponsiveBanner(id, anchorX, anchorY, posX, posY, maxWidth, maxHeight) → { ok, reason, size } (in-game banners drawn by the portal over the game; they show once ads are live on Gamealia, until then reason: "not-live"), ad.clearBanner(id), ad.clearAllBanners() |
| Player account | user.get(), user.getToken(), user.requestLogin(), user.onChange(cb) |
| Cloud save | data.load() → { ok, data }, data.get(key), data.set(key, value), data.remove(key), data.clear() |
| Rooms | room.getJoinCode(), room.getJoinKey(), room.getJoinPass(code?), room.joinFailed(reason, code?), room.inviteLink(code), room.showInvite(code), room.onJoin(cb), room.publish(room), room.unpublish() |
| Presence and friends | presence.setStatus(text), friends.list(), friends.invite(id, code), friends.onChange(cb) |
| Leaderboards | leaderboard.submit(board, value), leaderboard.get(board, { scope, season, limit, around }), leaderboard.show(board?) |
Events on Gamealia.events (a cc.EventTarget): localeChange (locale), adStart, adEnd, pause, resume, mute, unmute, userChange (user), roomJoin (code, key), friendsChange.
JavaScript-only features
Chat, store and the other extras of the SDK reference are on the raw SDK object, Gamealia.sdk (after init()), untyped:
const r = await Gamealia.sdk.chat.join("global");
Build
- Project > Build, platform Web Mobile (or Web Desktop), then Build.
- Upload the
build/web-mobilefolder, withindex.htmlat its root (or zip it as it is). - Keep the build's own files:
index.html,application.js,src/(settings.json,system.bundle.js,import-map.json),cocos-js/andassets/. If you use physics or another engine module that ships.wasmfiles, make sure they are in the upload.
Optional: to load the SDK before the engine starts, add <script src="https://gamealia.app/sdk/v1.js"></script> to the head of a custom build template (build-templates/web-mobile/index.ejs, made from the default one). Without it, Gamealia.ts loads the SDK when init() runs.
Already use another portal's Cocos package?
Remove it and move its calls to the Gamealia ones: loading done, gameplay start and stop, midgame and rewarded ads, mute. If its SDK was loaded from a script tag in a build template, our compatibility shim can take its place, as the migration guides explain.
Common autotest failures
gameplay_start/gameplay_stop: noGamealia.game.gameplayStart()/gameplayStop()calls.loading_stop: GamealiaBootstrap is not in the first scene, or Manual Loading Stop is on and the call is never reached.translations: texts set once frominit().localewithoutGamealia.events.on("localeChange", ...).- A file the page loads is missing: upload the whole
build/web-mobilefolder, not part of it.
Problems or questions: the Support chat in your dashboard, or hello@gamealia.app (Support).