Skip to contentGo to cookie choices
Skip to docs navigation

Bring a Phaser or HTML5 game

https://docs.zokogames.com/porting/phaser-html5

For a Phaser game, or any game written in plain JavaScript or TypeScript (Three.js, PixiJS, Babylon.js, a bare canvas), that already runs on other web game portals. These games call the portal SDK from JavaScript, so they have the shortest port: change the script tag, then rename the calls or load the compatibility shim. The full references are the Phaser page and plain HTML5 and libraries. The overall route is in bring your game.

1. Build settings#

Setting On ZokoGames
SDK script tag <script src="https://sdk.zokogames.com/zokogames-sdk-v1.js"></script> before your game script, in place of the other portal's tag. Keep the exact URL: the validator looks for it, and a bundled copy is flagged (sdk_bundled).
Paths Relative only. With Vite set base: "./"; root-absolute paths raise absolute_path. See relative paths.
Pre-compression None. Your page requests plain file names.
Archive The build output zipped with index.html at the archive root.
Canvas Sized from the window: Phaser.Scale.FIT with autoCenter: CENTER_BOTH, or the resize handler in sizing.

2. Rename the calls, or shim them#

Most web game portal SDKs share the shapes ZokoGames uses: init(), ad.requestAd(type, callbacks) with started, finished and error callbacks, gameplay start and stop, user, cloud save. Pick one route.

Rename (recommended). Point your code at window.ZokoGames.SDK and check the differences listed in migrating. The usual shape after the rename:

JavaScript
const SDK = window.ZokoGames?.SDK;                 // undefined if the script was blocked
let live = false;

async function startPlatform() {
  if (!SDK) return;
  await SDK.init();                                // never rejects
  live = SDK.environment !== "disabled";           // the game must also run when disabled
}

function showAd(type, pause, resume) {
  if (!live) return Promise.resolve(false);
  return new Promise((done) => {
    SDK.ad.requestAd(type, {
      adStarted: pause,
      adFinished: () => { resume(); done(true); },   // grant a reward only here
      adError: () => { resume(); done(false); },     // unfilled, adCooldown, adblock
    }).catch(() => { resume(); done(false); });
  });
}

Every SDK.game.*, SDK.user.*, SDK.ad.* and SDK.banner.* call returns a promise, and any of them can reject (for example sdkNotInitialized, sdkDisabled, rateLimited or unexpectedError; SDK.data is the exception: it is synchronous and throws). Code ported from a portal whose calls never failed often fires them and forgets, which leaves an unhandled rejection in the console, or a stuck pause when the call that should resume the game failed. Add .catch(() => {}) (or try/await) to every call you do not read the result of, and resume the game in the error path.

Shim (quick port). Keep your call sites and add the shim after the SDK, naming the global your game already reads:

HTML
<script src="https://sdk.zokogames.com/zokogames-sdk-v1.js"></script>
<script src="zokogames-compat-v1.js" data-global="YourOldGlobal"></script>

Download zokogames-compat-v1.js from https://www.zokogames.com/sdk/zokogames-compat-v1.js and ship it in your zip next to index.html. It forwards every call, translates the common differences (an old error spelling, callback-style calls, renamed loading calls) and runs init() for games that never call it. What it translates, and what it does not, is in migrating. Plan to rename later: the shim is a bridge.

Phaser plugin. For Phaser, the ZokoGames Phaser plugin does the ad pause for you: requestAd sleeps the game loop and mutes sound on start and restores both on finish and on error. If your old code paused only one scene, switch to the plugin or to game.loop.sleep().

Your game does With the SDK
Midgame ad (an interstitial or commercial break) or rewarded ad SDK.ad.requestAd("midgame", callbacks) or "rewarded", as in showAd above. Any other type string rejects with invalidArgument, and ads before the game starts (prerolls) are not shown.
Gameplay start and stop SDK.game.gameplayStart() and gameplayStop(). Call gameplayStart() before the first midgame request: until then the portal refuses it with adCooldown.
Loading finished SDK.game.loadingStart(), loadingProgress(0..100), then loadingStop() once the first screen can be played; the Phaser plugin's trackLoading(this.load) does it for a loader. Nothing sends these for you in plain HTML5.
Player name, sign-in SDK.user.getUser() resolves null for a guest (not an error); SDK.user.showAuthPrompt() opens the sign-in dialog.
Mute Apply SDK.game.settings.muteAudio at start and in addSettingsChangeListener.
Cloud save SDK.data.setItem(key, value) and getItem(key), strings only. Moving old localStorage saves: data.
Leaderboard score SDK.user.submitScore({ encryptedScore, score }) on a board created in the console. The page can encrypt with Web Crypto, see leaderboards.
Purchases SDK.store.getCatalogItems(), buyItem(itemId), consumeItem(sku, quantity). Purchases are test purchases for now (purchases).

3. Build size and mobile#

  • Budget: 1,500 files, 250 MB unpacked, about 50 MB initial download (20 MB for mobile), estimated from uncompressed sizes.
  • Minify and tree-shake; pack textures into atlases; WebP or KTX2 textures; modest audio bitrates.
  • Load later levels after the first scene, not in one big preload.
  • Cap devicePixelRatio on phones and start audio from a pointer or key event. See mobile.

4. Test before you submit#

  1. Serve the game from localhost. The SDK starts in local mode: a three-second overlay per ad, fake players, saves in localStorage. Add ?sdk_debug=true to log every call, ?ad_response=unfilled to force ad errors and ?user_response=logged_out for guests. A second midgame within three minutes fails with adCooldown. See local mode.
  2. Open the Preview tool with your local address and watch the checklist tick.
  3. Upload the zip and open the game's Preview and QA tab in the developer console to run it in the portal frame with ads on (build preview).

Checklist#

  • ZokoGames SDK script tag; the other portal's tag and any bundled SDK copy removed.
  • Relative paths; index.html at the archive root.
  • Calls renamed, or the shim loaded after the SDK with data-global.
  • init() first; the game plays when the SDK is missing or disabled.
  • The whole loop and audio pause on ad start and resume on finish and error; rewards only on finish.
  • Saves through SDK.data; scores on a board created in the console.
  • Other portal's logos, links and sitelock removed.
  • Tested on localhost, in the Preview tool and in Preview and QA.

Next#

Something unclear, wrong or missing on this page? Tell us through support · Test your game in the preview tool