Skip to content

Cocos

AI Summary

A short gist of this page, generated for you.

Powered by AI. Summaries can miss nuance — when in doubt, read the page.

Cocos Creator games are JavaScript, so they use the standard SDK directly. Add the script to your web build's page, then call FunOxSDK from your TypeScript.

#Install

Add the SDK to the page your web build uses, before the engine's own scripts:

html
<script src="https://funox.com/sdk/v1/funox-sdk.js"></script>

The usual way is a custom build template, so the line survives every build: put a copy of the page under build-templates/web-mobile/ (or web-desktop/) in your project and add the script tag there. The file is index.ejs in Cocos Creator 3 and index.html in Cocos Creator 2.

#Initialize

In the main script of your first scene:

typescript
import { _decorator, Component } from 'cc';
const { ccclass } = _decorator;

declare const FunOxSDK: any;

@ccclass('Boot')
export class Boot extends Component {
    start() {
        FunOxSDK.init()
            .catch((err: any) => console.warn('Funox SDK init failed', err))
            .then(() => this.loadMainMenu());
    }

    loadMainMenu() {
        // load your first real scene
    }
}

#Gameplay signals

typescript
FunOxSDK.gameplayStart(); // active play begins
FunOxSDK.gameplayStop();  // play ends or is interrupted
FunOxSDK.happyTime();     // a great moment

#Ad break

typescript
import { director } from 'cc';

declare const FunOxSDK: any;

function onLevelComplete() {
    FunOxSDK.gameplayStop();

    director.pause();
    muteAudio(); // your own audio handling

    FunOxSDK.commercialBreak()
        .catch(() => {})
        .then(() => {
            unmuteAudio();
            director.resume();
            loadNextLevel();
        });
}

Rewarded ads:

typescript
FunOxSDK.rewardedBreak('extra_life').then((result: any) => {
    if (result.completed) {
        grantExtraLife();
    }
});

#Save data

typescript
FunOxSDK.saveProgress({ level: 5, score: 12400 }).catch(() => {
    // guest player: keep a local copy instead
});

FunOxSDK.loadProgress().then((data: any) => {
    if (data) applySave(data);
});

#Build settings

  • Build for Web Mobile for the best mobile compatibility.
  • Upload the build output folder, with index.html at its top level, and choose Cocos as the engine.
  • Keep the first scene small so the game starts quickly.