Skip to content

Latest commit

History

History
68 lines (60 loc) 路 1.83 KB

INTEGRATION.md

File metadata and controls

68 lines (60 loc) 路 1.83 KB

CERE Games SDK integration guide

In order to integrate CERE Games SDK into a game, the game developer needs to follow these steps:

  1. Install the SDK package
npm install --save @cere/games-sdk
  1. Create and initialize the SDK instance as soon as possible on on the game's page (eg. on page load)
const { GamesSDK } = require("@cere/games-sdk");

window.CereGamesSdk = new GamesSDK({
  gameId: 'tower-game',

  gameInfo: {
    name: 'Tower Game',
    tags: ['towergame', 'web3', 'gamer'],
    url: window.location.href,
    // logoUrl: "http://..."
  },

  onReady: (sdk) => {
    // ...
  },

  onWalletDisconnect: () => {
    // ...
  },
});

window.CereGamesSdk.init();
  1. Show the preloader modal as soon as the SDK is ready
new GamesSDK({
  // ...
  onReady: (sdk) => {
    window.gamesSdkPreloader = sdk.showPreloader({
      onStart:() => {
        // Start the game
      }
    });
  },
});
  1. Set the preloader ready as soon as all game assets are loaded and the game is ready to be played
window.gamesSdkPreloader.setReady();
  1. Save the player's score when the game is over
window.CereGamesSdk.saveScore(score).then(() => {
  // The score is saved
});
  1. Show the leader board right after the score is saved
window.CereGamesSdk.showLeaderboard({
  onPlayAgain: () => {
    // Restart the game
  }
});

Helpful links