HypercasualGaming SDK
Guide

Function reference

Everything the HGSDK object offers. The SDK creates it as soon as it loads, before your game's code runs.

Lifecycle of a game

Cover→gameplayStart()→playing→gameplayStop()→menu or end screen

Gameplay

FunctionWhat it's for
HGSDK.gameplayStart()Gameplay starts or continues. From here on, gestures belong to the game and play time counts.Required
HGSDK.gameplayStop()Gameplay stops: the player loses, pauses or goes to the menu. Play time stops counting and the player can swipe to switch games.Required
HGSDK.sendScore(score)Sends a score (whole number from 0 to 10,000,000; decimals are rounded down). If the player is signed in, it's saved as their high score when it beats the previous one and appears in the rankings. It doesn't stop gameplay. Only if your game has a score.Optional

Each player has a single score in each ranking (today, this week and all time): their best. Sending many scores only keeps the highest one.

Ads

Your game never loads ads by itself: it asks the website with HGSDK.showAd({ type }) and the website shows the ad on top of the game, frozen and muted meanwhile. reward returns a promise with { rewarded }. If you don't use promises, pass a function as second argument: it's called when the ad ends and receives that same { rewarded }. break returns nothing: your game continues on its own when the ad ends.

typeWhenReturns
'break'Between runs, for example before playing again.Nothing. Your game continues on its own when the ad ends.
'reward'The player chooses to watch it in exchange for something in the game (revive, continue…).rewarded: true only if they watched it to the end. Give the prize only then.
// one revive per run, only if the player asks for it
// option 1: with a promise
async function offerRevive() {
  const { rewarded } = await HGSDK.showAd({ type: 'reward', name: 'revive' });
  if (rewarded) revive(); else gameOver();
}

// option 2: with a function as second argument
function offerRevive() {
  HGSDK.showAd({ type: 'reward', name: 'revive' }, function (r) {
    if (r.rewarded) revive(); else gameOver();
  });
}

// before playing again, never before the first run
if (runs > 0) HGSDK.showAd({ type: 'break' });
runs++;
startRun();

Several rewards

Your game can have as many rewards as it needs (revive, double the coins, a skin…). Give each one its own name: a short label (up to 40 characters) that says which reward it is. In JavaScript, each showAd call receives its own answer, so each reward handles its own result:

// when they ask to revive
async function offerRevive() {
  const { rewarded } = await HGSDK.showAd({ type: 'reward', name: 'revive' });
  if (rewarded) revive(); else gameOver();
}

// at another moment: to double their coins
async function offerDoubleCoins() {
  const { rewarded } = await HGSDK.showAd({ type: 'reward', name: 'double_coins' });
  if (rewarded) coins *= 2;
}

Version

HGSDK.version is the version of the SDK that's loaded, for example "1.8.7" (read only). You don't need it to integrate your game.