ยทยทยท$AIGM

SDK Documentation

Integrate your game with AI Games platform in minutes

SDK v1.0.0

๐Ÿš€ Quick Start

Integrate the AI Games SDK into your game in 3 steps.

1
Add SDK Script
HTML
<script src="/sdk/v1/aigames-sdk.js"></script>
2
Initialize SDK
JS
AIGM.init();

AIGM.on('ready', function(features) {
  console.log('SDK ready!', features);
  AIGM.loading.start();
  // ... load your game assets ...
  AIGM.loading.stop();
  AIGM.game.gameplayStart();
});
3
Add Ads
JS
// Interstitial (between levels)
await AIGM.ad.commercialBreak();

// Rewarded (optional bonus)
const result = await AIGM.ad.rewardedBreak();
if (result.viewed) givePlayerReward();

๐ŸŽฎ Lifecycle API

MethodDescription
AIGM.init(config?)Initialize SDK. config: { debug, heartbeatInterval, gameId }
AIGM.loading.start()Notify asset loading started
AIGM.loading.stop()Asset loading complete (game ready)
AIGM.game.gameplayStart()Actual gameplay started
AIGM.game.gameplayStop()Gameplay paused (menu, level transition)
AIGM.game.happytime()Celebration effect (boss kill, highscore). 30s cooldown, 10/session

๐Ÿ“บ Ads API

Supports both Promise and Callback patterns.

Promise
// Promise style (recommended)
const result = await AIGM.ad.requestAd('rewarded');
if (result.viewed) {
  givePlayerReward();
}

// Convenience methods
await AIGM.ad.commercialBreak();  // interstitial
await AIGM.ad.rewardedBreak();    // rewarded
Callback
// Callback style
AIGM.ad.requestAd('interstitial', {
  adStarted: function() {
    pauseGame();
    muteAudio();
  },
  adFinished: function() {
    resumeGame();
    unmuteAudio();
  },
  adError: function(error) {
    console.warn('Ad failed:', error);
    resumeGame();
  }
});
โš ๏ธAlways pause your game and mute audio when an ad starts. Pre-roll ads (before game start) are prohibited.

๐Ÿ‘ค User Module

JS
const user = AIGM.user.getUser();
// { isLoggedIn: true, displayName: "Player1", avatar: "https://...", id: "usr_xxx" }
// or { isLoggedIn: false }

// Request login
AIGM.user.showAuth();

// Listen for auth changes
AIGM.on('auth:changed', function(user) {
  if (user.isLoggedIn) {
    showWelcome(user.displayName);
  }
});

๐Ÿ’พ Data Storage

Save game progress to the server. Logged-in users get cloud sync, guests use localStorage.

JS
// Save progress
await AIGM.data.setItem('level', '5');
await AIGM.data.setItem('score', '12500');

// Load progress
const level = await AIGM.data.getItem('level');
const score = await AIGM.data.getItem('score');

// Delete
await AIGM.data.removeItem('level');
await AIGM.data.clear(); // remove all
LimitValue
Value size (per key)64 KB
Keys (per game)100
Total quota (user+game)1 MB

๐Ÿงช Testing

Test mode auto-activates on localhost. Ads run as mocks and all events are logged to console.

JS
// Test mode is auto-detected on localhost.
// Or force it with URL param: ?aigm_debug=true

// Debug API (test mode only)
AIGM.debug.getLog();                  // All events
AIGM.debug.simulateAd('rewarded');    // Simulate ad
AIGM.debug.setAdDelay(3000);          // Mock ad delay (ms)
AIGM.debug.simulateEvent('pause');    // Simulate event

// Check SDK state
console.log(AIGM.getState());
// { ready, standalone, testMode, authenticated, sdkVersion }

๐Ÿ“‹ Full Example

HTML
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>My AI Game</title>
  <script src="/sdk/v1/aigames-sdk.js"></script>
</head>
<body>
  <canvas id="game" width="960" height="540"></canvas>
  <script>
    // 1. Initialize SDK
    AIGM.init();

    // 2. Wait for platform ready
    AIGM.on('ready', function(features) {
      console.log('Platform ready:', features);

      // 3. Start loading assets
      AIGM.loading.start();
      loadGameAssets().then(function() {
        AIGM.loading.stop();
        startGame();
      });
    });

    // 4. Handle platform events
    AIGM.on('pause', function() { pauseGame(); });
    AIGM.on('resume', function() { resumeGame(); });
    AIGM.on('mute', function(muted) { setMute(muted); });

    function startGame() {
      AIGM.game.gameplayStart();
    }

    // 5. Show ads between levels
    async function onLevelComplete(level) {
      AIGM.game.gameplayStop();

      // Save progress
      await AIGM.data.setItem('lastLevel', String(level));

      // Show interstitial
      await AIGM.ad.commercialBreak();

      // Boss defeated? Celebrate!
      if (level % 5 === 0) AIGM.game.happytime();

      AIGM.game.gameplayStart();
    }

    // 6. Rewarded ads for bonus
    async function watchAdForBonus() {
      AIGM.game.gameplayStop();
      var result = await AIGM.ad.rewardedBreak();
      if (result.viewed) {
        givePlayerCoins(100);
      }
      AIGM.game.gameplayStart();
    }
  </script>
</body>
</html>

๐ŸŽฏ Playground

Write code and test it live