Skip to main content

Cocos

Funox supports Cocos Creator HTML5 builds via the standard HTML5 SDK plus a small Cocos wrapper.

Install

  1. In your build-templates/web-mobile/index.html (or web-desktop/index.html), add the Funox SDK before the Cocos bootstrap:

    HTML1 line
    1<script src="https://sdk.funox.com/funox-sdk-v1.js"></script>
  2. Download the optional funox-cocos.js helper from the Developer Portal and place it in assets/scripts/.

Initialize

In your bootstrap scene's main script:

TypeScript12 lines
1import { _decorator, Component } from 'cc';2const { ccclass } = _decorator;3 4declare const Funox: any;5 6@ccclass('Boot')7export class Boot extends Component {8    async start() {9        await Funox.SDK.init();10        console.log('Funox SDK ready');11    }12}

Lifecycle

TypeScript5 lines
1Funox.SDK.game.gameplayStart();2Funox.SDK.game.gameplayStop();3Funox.SDK.game.loadingStart();4Funox.SDK.game.loadingStop();5Funox.SDK.game.happytime();

Video ads

TypeScript5 lines
1Funox.SDK.ad.requestAd('midgame', {2    adStarted:  () => cc.audioEngine.pauseAll(),3    adFinished: () => cc.audioEngine.resumeAll(),4    adError:    () => cc.audioEngine.resumeAll(),5});

Save data

TypeScript2 lines
1Funox.SDK.data.setItem('highScore', '12450');2const score = Funox.SDK.data.getItem('highScore');

Build settings

  • Template: web-mobile for best mobile compatibility
  • Compression: gzip or brotli at your CDN
  • Auto-merge JSON: on
  • Subpackages: keep the initial subpackage ≤ 20 MB for mobile featuring