Lifecycle and storage
Pause your game in one place, keep the player's progress, and use the small device helpers.
Show and hide
GOOF.game.onHide fires when the host deactivates your game, for example when the player scrolls away or switches apps. It also fires before every ad and payment sheet. GOOF.game.onShow fires when your game is active again, also after every ad and payment sheet.
function pause() { running = false; audio.suspend(); }
function resume() { running = true; audio.resume(); }
GOOF.game.onHide(pause);
GOOF.game.onShow(resume);
// later, to remove them:
GOOF.game.offHide(pause);
GOOF.game.offShow(resume);
Pause the loop and the audio here and nowhere else. Then ads, payments and app switches all behave the same.
Loading and ready
GOOF.game.setLoadingProgress(0.5); // a number from 0 to 1
GOOF.game.setLoadingProgress(1);
GOOF.game.gameReady(); // the first screen can be played
Storage
The storage calls keep values in the host's save for your game, under the key __goof. On the mock host they use localStorage. All of them return promises.
await GOOF.game.setStorage('best', 1200);
const best = await GOOF.game.getStorage('best');
await GOOF.game.removeStorage('best');
Cloud storage style
For code written for the cloud storage style of API, the same data is reachable with key lists:
await GOOF.game.setUserCloudStorage({ KVDataList: [{ key: 'level', value: '7' }] });
const res = await GOOF.game.getUserCloudStorage({ keyList: ['level'] });
Player id
const { code, anonymousId } = await GOOF.game.login();
anonymousId stays the same for a player in your game. Use it to tell players apart, not to identify a person.
Device helpers
const info = GOOF.game.getSystemInfoSync();
// { platform, language, screenWidth, screenHeight, pixelRatio,
// safeArea: { top, bottom, left, right }, SDKVersion, host }
GOOF.game.vibrateShort();
GOOF.game.vibrateLong();
GOOF.game.shareAppMessage({ title: 'I scored 1200!' });
GOOF.game.reportScore(1200);
GOOF.game.logEvent('level_done', { level: 7 });
Keep buttons inside safeArea so they are not under a notch or a home bar.