Skip to content

HTML5 / JavaScript

AI Summary

A short gist of this page, generated for you.

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

This is the reference integration. It works for plain canvas games and for any JavaScript library or engine: PixiJS, Three.js, Babylon.js, PlayCanvas, Kaboom and your own code.

#Install

Add the SDK to your index.html, before your game's scripts:

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

It exposes the global FunOxSDK.

#Initialize

javascript
FunOxSDK.init()
  .then(function () { bootGame(); })
  .catch(function (err) {
    console.warn('Funox SDK init failed', err);
    bootGame(); // start anyway
  });

With async / await:

javascript
async function main() {
  try {
    await FunOxSDK.init();
  } catch (err) {
    console.warn('Funox SDK init failed', err);
  }
  bootGame();
}

main();

#Minimal integration

This covers the four required calls.

javascript
FunOxSDK.init().then(showMainMenu, showMainMenu);

function startGameplay() {
  FunOxSDK.gameplayStart();
}

function stopGameplay() {
  FunOxSDK.gameplayStop();
}

function onLevelComplete() {
  stopGameplay();
  game.pause();
  game.mute(true);

  FunOxSDK.commercialBreak()
    .catch(function () {})
    .then(function () {
      game.mute(false);
      game.resume();
      loadNextLevel();
    });
}

#PixiJS

javascript
async function main() {
  const app = new PIXI.Application({ width: 800, height: 600 });
  document.body.appendChild(app.view);

  try {
    await FunOxSDK.init();
  } catch (e) {
    // continue anyway
  }

  startGameLoop(app);
  FunOxSDK.gameplayStart();
}

main();

#Bundlers and TypeScript

Keep loading the SDK with the script tag even if the rest of your game is bundled with Vite, webpack or similar — do not import a copy of it into your bundle.

In TypeScript, declare the global once:

typescript
declare const FunOxSDK: any;

#Common patterns

#React to the platform

javascript
FunOxSDK.on('pause', function () { game.pause(); });
FunOxSDK.on('resume', function () { game.resume(); });
FunOxSDK.on('mute', function () { game.mute(true); });
FunOxSDK.on('unmute', function () { game.mute(false); });

See Platform events.

#Pause heavy work when the tab is hidden

javascript
document.addEventListener('visibilitychange', function () {
  if (document.hidden) {
    game.pause();
    FunOxSDK.gameplayStop();
  } else {
    game.resume();
    FunOxSDK.gameplayStart();
  }
});

#Handle private-browsing localStorage safely

javascript
function safeGet(key) {
  try { return localStorage.getItem(key); }
  catch (e) { return null; }
}

function safeSet(key, value) {
  try { localStorage.setItem(key, value); }
  catch (e) { /* private browsing: ignore */ }
}

#Build tips

  • Bundle all assets — no external CDNs.
  • Ship WebP or AVIF images where possible.
  • Keep the game folder under the 100 MB upload limit; smaller loads faster.
  • Keep index.html at the top level of the folder you upload.

#Where to go next