GameMaker
With the official HGSDK extension you call the SDK directly from GML, without writing JavaScript. It works when you export your game to HTML5.
1. Import the extension
- Open your project and go to Tools → Import Local Package.
- Choose
HGSDK_v1.yymps, click Add All and then Import. - The HGSDK extension appears in the Asset Browser with these functions:
| GML function | What it's for | |
|---|---|---|
hg_gameplay_start() | Gameplay starts or continues. | Required |
hg_gameplay_stop() | Gameplay stops: losing, pausing or going to the menu. | Required |
hg_send_score(score) | Sends the score and, if the player is signed in, saves their high score. It doesn't stop gameplay. Only if your game has a score. | Optional |
hg_ad_break() | Ad between runs. It returns nothing: the game is frozen during the ad and continues on its own. | Optional |
hg_ad_reward(name) | Ad the player chooses to watch in exchange for something. The result arrives at the Asynchronous → Social event (see section 4). | Optional |
2. Call the functions from GML
// When gameplay starts
hg_gameplay_start();
// When the player loses: send the score (optional, a whole number) and stop
hg_send_score(score);
hg_gameplay_stop();
// Your pause menu
hg_gameplay_stop(); // when opening your pause menu
hg_gameplay_start(); // when closing it
3. Export to HTML5 and add the SDK
- Choose the HTML5 target and export with Create Executable, as a folder or as a .zip.
- Open the exported
index.htmland add the SDK line right before the game's script (the one in thehtml5game/folder):
<script src="/sdk/v1/hg-sdk.js"></script>
<script type="text/javascript" src="html5game/YourGame.js"></script>
GameMaker generates index.html again on every export: repeat this step each time, or use your own index.html as an included file in the HTML5 options.
Make your rooms portrait (for example 720 × 1280) and, in Game Options → HTML5 → Graphics, choose Scaling: Keep aspect ratio so the game fits any screen.
4. Ads (optional)
Your game doesn't load ads by itself: it asks the website and the website shows them on top, freezing and muting the game meanwhile. There are two kinds: break (between runs) and reward (the player chooses to watch it in exchange for something in the game). Don't report that gameplay stops or continues because of an ad: the SDK freezes and resumes your game on its own.
// Ad between runs, never before the first one: the game stays frozen until it ends, just carry on
if (global.runs > 0) hg_ad_break();
global.runs++;
start_game();
// Ad the player chooses to watch
hg_ad_reward("revive"); // when they ask to revive
hg_ad_reward("double_coins"); // at another moment: to double their coins
// Asynchronous → Social event
if (ds_map_exists(async_load, "type") && async_load[? "type"] == "hg_ad") {
var ok = async_load[? "rewarded"]; // 1 only if they watched it to the end
switch (async_load[? "name"]) { // the name you passed to hg_ad_reward
case "revive": if (ok) revive(); else game_over(); break;
case "double_coins": if (ok) coins *= 2; break;
}
}
In that event, async_load is a map with these keys:
type: always"hg_ad". It tells you the event comes from the SDK.name: the name you passed tohg_ad_reward, to know which reward it was.rewarded:1if they watched it to the end (give the prize),0if not.
A reward can come back without an ad at any moment (none available or ads switched off): your game has to keep working. And a reward never gives score — revives, continues, extra lives or skins are fine.
5. What you don't need to do
- Pause and sound when switching games: the SDK freezes GameMaker's loop and audio on its own, and shows “Tap to continue” when the player comes back.
- Mute: the website's sound button mutes your game on its own, music included.
- Start screen: don't make one. The website shows the cover with your logo, the name and “TAP TO PLAY”; the first tap anywhere must start the game.
- Saving high scores: don't use files or
ini; if your game has a score, the website saves the high score of each signed-in player withhg_send_score.
6. Test it
Upload the exported folder (or its .zip) in Upload game and tap 🧪 Test before submitting. More details in Test and publish.
HypercasualGaming