Godot
AI Summary
A short gist of this page, generated for you.
Powered by AI. Summaries can miss nuance — when in doubt, read the page.
Godot's web export can call JavaScript directly, so there is no plugin to install. You add the SDK script to the exported page and talk to it through JavaScriptBridge.
#Install
In Project → Export → Web, find HTML → Head Include and add:
<script src="https://funox.com/sdk/v1/funox-sdk.js"></script>#An autoload for the SDK
Create funox.gd and register it as an Autoload named Funox (in Project → Project Settings).
extends Node
signal ad_finished
var _sdk = null
var _on_ad_done = null # kept here so Godot does not free the callback
func _ready() -> void:
# Keep running while the game is paused for an ad
process_mode = Node.PROCESS_MODE_ALWAYS
if OS.has_feature("web"):
_sdk = JavaScriptBridge.get_interface("FunOxSDK")
_on_ad_done = JavaScriptBridge.create_callback(_ad_done)
if _sdk:
_sdk.init()
func gameplay_start() -> void:
if _sdk:
_sdk.gameplayStart()
func gameplay_stop() -> void:
if _sdk:
_sdk.gameplayStop()
func happy_time() -> void:
if _sdk:
_sdk.happyTime()
# Pause and mute before calling this. Wait for the ad_finished signal to resume.
func commercial_break() -> void:
if not _sdk:
ad_finished.emit.call_deferred() # deferred so a caller can await the signal
return
_sdk.commercialBreak().then(_on_ad_done, _on_ad_done)
func _ad_done(_args) -> void:
ad_finished.emit()Keep the callback in a member variable, as above. Godot frees a JavaScript callback that nothing references. Outside a web export _sdk stays null, so every function is safe to call when you run the game from the editor.
#Use it
func start_level() -> void:
Funox.gameplay_start()
func on_level_complete() -> void:
Funox.gameplay_stop()
get_tree().paused = true
AudioServer.set_bus_mute(0, true)
Funox.commercial_break()
await Funox.ad_finished
AudioServer.set_bus_mute(0, false)
get_tree().paused = false
load_next_level()#Other calls
Any SDK call that needs no answer can be made in one line:
JavaScriptBridge.eval("FunOxSDK.trackEvent('level_started', { level: 3 })")
JavaScriptBridge.eval("FunOxSDK.saveProgress({ level: 5, score: 12400 }).catch(function(){})")For calls that return data, such as loadProgress() or rewardedBreak(), use the same pattern as commercial_break(): pass a callback created with JavaScriptBridge.create_callback() to .then(). The result arrives as the first item of the callback's argument array.
#Godot 3
The same approach works with the older names: JavaScript.get_interface("FunOxSDK"), JavaScript.eval(...) and JavaScript.create_callback(self, "_ad_done").
#Export settings
- Export with the Web preset and upload the exported folder, with the main HTML file named
index.html. - Choose Godot as the engine in the upload form.
- Turn off the custom splash screen if you can; players should reach gameplay quickly.