···$AIGM

SDK 문서

AI Games 플랫폼에 게임을 연동하세요 — 몇 분이면 됩니다

SDK v1.0.0

🚀 Quick Start

3단계로 AI Games SDK를 게임에 연동하세요.

1
SDK 스크립트 추가
HTML
<script src="/sdk/v1/aigames-sdk.js"></script>
2
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
광고 연동
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?)SDK 초기화. config: { debug, heartbeatInterval, gameId }
AIGM.loading.start()에셋 로딩 시작 알림
AIGM.loading.stop()에셋 로딩 완료 (게임 준비됨)
AIGM.game.gameplayStart()실제 게임플레이 시작
AIGM.game.gameplayStop()게임플레이 중단 (메뉴, 레벨 전환)
AIGM.game.happytime()축하 이펙트 (보스 격파, 신기록). 30초 쿨다운, 세션당 10회

📺 Ads API

Promise와 Callback 두 가지 방식을 모두 지원합니다.

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();
  }
});
⚠️광고가 시작되면 반드시 게임을 일시정지하고 사운드를 음소거하세요. 프리롤 광고(게임 시작 전 광고)는 금지입니다.

👤 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

게임 진행 상황을 서버에 저장합니다. 로그인 유저는 클라우드 동기화, 비로그인 유저는 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
제한
값 크기 (키당)64 KB
키 수 (게임당)100
총 용량 (유저+게임)1 MB

🧪 Testing

localhost에서 자동으로 테스트 모드가 활성화됩니다. 광고는 mock으로 동작하고, 모든 이벤트가 콘솔에 로깅됩니다.

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

코드를 작성하고 실행해보세요