Skip to contentGo to cookie choices
Skip to docs navigation

Bring a Cocos game

https://docs.zokogames.com/porting/cocos

For a Cocos Creator 3 game that already ships as a Web Mobile or Web Desktop build on other web game portals. Names in the ZokoGames module match the JavaScript SDK one to one, so the port is mostly swapping one object for another. The full reference is the Cocos engine page. The overall route is in bring your game.

1. Build settings#

Copy assets/zokogames/ into your project's assets/ folder (Cocos: install). Then:

Setting On ZokoGames
Build templates Paste build-templates/zokogames-sdk-snippet.html (the SDK script tag) into the <head> of build-templates/web-desktop/index.ejs and build-templates/web-mobile/index.ejs, and remove the other portal's tag.
Build target Web Mobile or Web Desktop.
Remote server address Empty: everything ships in the zip, with relative paths.
Pre-compression None. Cocos requests plain file names.
Resolution policy A design resolution with Fixed Height or Show All, so the game fits a frame that changes with fullscreen and rotation.

Details: web export settings that matter.

2. Replace the platform calls#

Remove the other portal's module and calls first. import ZokoSDK from "./zokogames/ZokoSDK";, await ZokoSDK.init() once, then map each call. Calls return promises; the data calls are synchronous (mapping).

Your game does With ZokoSDK
Start the SDK await ZokoSDK.init(); ZokoSDK.isAvailable is false when the SDK is disabled, and the game must still run.
Loading finished ZokoSDK.game.loadingStop() once the first scene runs (optionally loadingStart() and loadingProgress(p) before it). The module does not send these on its own.
Gameplay start and stop ZokoSDK.game.gameplayStart() and gameplayStop().
Midgame (interstitial) or rewarded ad await ZokoSDK.ad.requestAd(type, { adStarted, adFinished, adError }). Pause in adStarted; resume in a finally, because the call rejects without calling adError when it cannot start. Grant a reward only after adFinished.
Cloud save ZokoSDK.data.setItem(key, value), getItem(key). On the web, sys.localStorage is the browser's localStorage and can be mirrored with mirrorLocalStorage.
Leaderboard score ZokoSDK.user.submitScore(...) for a signed-in player, on a board created in the console. No wrapper builds the encrypted payload; a browser build can use Web Crypto, see leaderboards.
Purchases ZokoSDK.store.getCatalogItems, buyItem, consumeItem. Purchases are test purchases for now (purchases).
Sign-in prompt, player ZokoSDK.user.showAuthPrompt(), ZokoSDK.user.getUser().

A complete component is in a working component.

The compatibility shim can stand in for another portal's JavaScript global during a quick port, but the ZokoSDK module is the cleaner route for Cocos: it adds the simulator, typed errors and banner placement on nodes.

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.
  • Auto Atlas, ETC2 or ASTC textures for mobile, OGG or MP3 audio at modest bitrates.
  • Asset Bundles loaded after the first scene; unused engine modules off in Project Settings > Feature Cropping.
  • Release unused bundles on phones and start music from a "tap to play" screen. See mobile.

4. Test before you submit#

  1. In the Creator editor the simulator answers (ZokoSDK.isSimulated). Call ZokoSDK.configureSimulator(options) before init() to force ad errors, a logged-out player or a disabled SDK.
  2. A web preview or build on localhost runs the real SDK's local mode, which also enforces the three-minute midgame cooldown. If the SDK script is blocked, init() falls back to the simulator; check ZokoSDK.isSimulated in your test builds. See Cocos: test locally.
  3. Upload the zip (build folder contents, index.html at the archive root) 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#

  • Module copied; SDK snippet in both build templates; the other portal's module and tag removed.
  • Remote server address empty; plain file names.
  • await ZokoSDK.init() first; the game plays when isAvailable is false.
  • Gameplay start and stop at the right moments.
  • Ads resume in a finally; rewards only after adFinished.
  • Saves through ZokoSDK.data; scores on a board created in the console.
  • Other portal's logos, links and sitelock removed.
  • Tested on localhost 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