运行时

NG SDK

轻量浏览器 SDK,用于 iframe 内的加载状态、进度、分数、存档和钱包能力。

快速接入

从 sandbox 域引入 SDK,游戏可玩后调用 NG.ready(),并使用异步 save/load 完成存档。

包含 NG.ready、NG.load、NG.score 和 NG.save 的 SDK 快速接入代码截图。
SDK 接入只需要一个轻量浏览器脚本:上报 ready、读取存档、提交分数并保存进度。
<!doctype html>
<html>
<head><meta charset="utf-8"><title>My Game</title></head>
<body>
  <canvas id="stage" width="600" height="600"></canvas>
  <script src="https://sandbox.newgame.win/sdk/ng.js"></script>
  <script>
    const high = await NG.load('high_score') || 0
    function onGameOver(score) {
      NG.score(score, { level: 4 })
      if (score > high) NG.save('high_score', score)
    }
    NG.ready()
  </script>
</body>
</html>

核心方法

方法用途
NG.ready()通知平台隐藏加载界面。
NG.progress(value)上报 0 到 1 的加载进度。
NG.score(score, payload?)提交排行榜分数。
NG.save(key, value)为匿名或登录玩家持久化 JSON 数据。
NG.load(key)读取存档值,未命中返回 null。
NG.delete(key)删除一条存档。
NG.balance / earn / spend为登录玩家使用平台钱包 API。