Asobiai SDK

Every game published on Asobiai automatically gets the Asobiai SDK (window.AIGame). Nothing to install: call a function from your game to add leaderboards, saves, trophies, tallies and online multiplayer.

v2.7.0Check it from your game with window.AIGame?.version.Changelog

The Asobiai SDK in a comic
  1. Asobi: “High score! I want to compare with everyone.”
  2. Ai: “Just call one line on game over!” (AIGame.submitScore(score))
  3. Asobi: “Now there's a leaderboard!”
  4. Ai: “I'll tell you about errors, too.” Asobi: “That makes fixing easy!”

What it does

Call it with ?.

window.AIGame exists only when the game is served by Asobiai. It's missing when you open the HTML file directly, so call it with ?., like window.AIGame?.submitScore(score). The game then still runs without errors outside Asobiai.

js
// With ?., nothing happens when AIGame is missing
window.AIGame?.submitScore(score);

// await it to use the result (undefined outside Asobiai)
const result = await window.AIGame?.submitScore(score);

Language (AIGame.locale)

AIGame.locale is the language the Asobiai page is shown in ('ja' / 'en' / 'ko' / 'zh-Hans' / 'zh-Hant'). Matching the game's text to it lets players from other countries enjoy your game. Outside Asobiai it follows the browser's language.

js
// Outside Asobiai, use the browser's language
const lang = window.AIGame?.locale ?? navigator.language;
const T = lang.startsWith("ja")
  ? { start: "タップでスタート", over: "ゲームオーバー" }
  : { start: "Tap to start", over: "Game over" };

What the SDK does on its own

  • Errors and console output are forwarded to the page and shown in a console only the creator sees (and included in the “Ask AI to fix” text).
  • Stops arrow keys and space from scrolling the page.
  • Enables WebGL's preserveDrawingBuffer so thumbnails can be captured.
  • If the iframe size settles after loading and no resize event arrives, it sends one (so games that size their canvas at startup don't stay a blank color).
  • AIGame.gameOver({ score }) signals game over (used for “next game” prompts in play mode).

Runtime environment

  • Each game runs in an iframe on its own domain ({gameId}.asobiaiplay.com). localStorage and IndexedDB are per game and isolated from other games and the main site.
  • Games run inside an iframe and cannot navigate the top page. Open links in a new tab.
  • External CDNs and APIs can be used.
  • Godot web exports (threads disabled) and Unity WebGL builds work if you upload the folder. Calling the SDK from an engine