Godot 4
Load the SDK from the Web export options and call it from GDScript with JavaScriptBridge.
1. Create an autoload for the SDK
Create the script hg_sdk.gd and add it in Project → Project Settings → Autoload with the name HG:
extends Node
# Calls the HypercasualGaming SDK only when the game runs on the web.
func _sdk(js: String) -> void:
if OS.has_feature("web"):
JavaScriptBridge.eval("if (window.HGSDK) HGSDK." + js)
func gameplay_start() -> void:
_sdk("gameplayStart()")
func gameplay_stop() -> void:
_sdk("gameplayStop()")
func send_score(score: int) -> void:
_sdk("sendScore(%d)" % score)
2. Call the functions
HG.gameplay_start() # when gameplay starts or continues
HG.gameplay_stop() # when gameplay stops (losing, pausing, menu)
HG.send_score(score) # optional: only if your game has a score
3. Export for the Web
- In Project → Export, add a Web preset.
- In its options, under HTML → Head Include, paste the SDK line. That way it's added on every export:
<script src="/sdk/v1/hg-sdk.js"></script>
- Turn off Thread Support (Godot 4.3 or later). The website doesn't send the special headers the threaded version needs.
- Export with
index.htmlas the file name (Godot uses the project name if you don't change it) and upload the resulting folder.
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.
# Add this to hg_sdk.gd (the autoload named HG)
signal ad_finished(rewarded: bool)
var _ad_cb
func ad_break() -> void:
if OS.has_feature("web"):
JavaScriptBridge.eval("window.HGSDK && HGSDK.showAd({type:'break'})")
func show_reward(name: String) -> void:
if not OS.has_feature("web"):
ad_finished.emit(false)
return
if _ad_cb == null:
_ad_cb = JavaScriptBridge.create_callback(_on_ad)
var window = JavaScriptBridge.get_interface("window")
window.hg_ad_cb = _ad_cb
JavaScriptBridge.eval("(window.HGSDK ? HGSDK.showAd({type:'reward', name:%s}) : Promise.resolve({rewarded:false})).then(function (r) { window.hg_ad_cb(r.rewarded ? 1 : 0); });" % JSON.stringify(name))
func _on_ad(args) -> void:
ad_finished.emit(args[0] == 1)
# Use it
func offer_revive() -> void: # when they ask to revive
# connect it right before each reward: it only fires once
HG.ad_finished.connect(_on_revive_ad, CONNECT_ONE_SHOT)
HG.show_reward("revive")
func _on_revive_ad(rewarded: bool) -> void:
if rewarded:
revive()
else:
game_over()
func offer_double_coins() -> void: # at another moment: to double their coins
HG.ad_finished.connect(_on_double_coins_ad, CONNECT_ONE_SHOT)
HG.show_reward("double_coins")
func _on_double_coins_ad(rewarded: bool) -> void:
if rewarded:
coins *= 2
var runs := 0
func play_again() -> void:
if runs > 0:
HG.ad_break() # between runs, never before the first one: it returns nothing
runs += 1
start_game()
Several rewards: give each one its own name in show_reward(name), a short label (up to 40 characters) that says which reward it is. Connect its own function right before each one: that's how you know which reward the answer belongs to.
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. Recommended settings
- Portrait window (for example 720 × 1280) with Stretch mode: canvas_items and Aspect: expand to fit any screen.
- No start screen of your own: the website shows the cover. Start the game with the first tap anywhere.
- Don't save high scores in files: if your game has a score, the website saves the best of each signed-in player with
HG.send_score. - Sound: the SDK pauses and mutes your game's audio on its own, following the website's pause and sound button.
- Size: Godot's Web export is fairly large; check the maximum allowed in Upload game.
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