In order to integrate CERE Games SDK into a game, the game developer needs to follow these steps:
npm install --save @cere/games-sdk
- 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();
- Show the preloader modal as soon as the SDK is ready
new GamesSDK({
// ...
onReady: (sdk) => {
window.gamesSdkPreloader = sdk.showPreloader({
onStart:() => {
// Start the game
}
});
},
});
- Set the preloader ready as soon as all game assets are loaded and the game is ready to be played
window.gamesSdkPreloader.setReady();
- Save the player's score when the game is over
window.CereGamesSdk.saveScore(score).then(() => {
// The score is saved
});
- Show the leader board right after the score is saved
window.CereGamesSdk.showLeaderboard({
onPlayAgain: () => {
// Restart the game
}
});