Skip to content
Random game

Godot games

Last updated 2026-11-19

This guide is for Godot 4.3 or newer with the Web export. You add the SDK script to the export, then call it from GDScript with JavaScriptBridge.

Export settings

In Project, Export, Web:

  • Head Include: add the SDK script and start it early:
<script src="https://games.foony.com/sdk/v1.js"></script>
<script>
  FreeGamesSdk.init();
  FreeGamesSdk.loadingStart();
</script>
  • Thread Support: off. A threaded export needs special headers (cross-origin isolation) that a game frame on another site can’t count on. Godot 4.3 added single-threaded web exports for this.
  • Canvas Resize Policy: Adaptive, so the game fills the frame.

An autoload script

Save this as free_games.gd and add it in Project Settings, Autoload, with the name FreeGames:

extends Node

var sdk: JavaScriptObject
var break_done_callback: JavaScriptObject
var rewarded_done_callback: JavaScriptObject
var mute_callback: JavaScriptObject
var on_break_done: Callable
var on_rewarded: Callable


func _ready() -> void:
	if not OS.has_feature("web"):
		return
	sdk = JavaScriptBridge.get_interface("FreeGamesSdk")
	break_done_callback = JavaScriptBridge.create_callback(_on_break_done)
	rewarded_done_callback = JavaScriptBridge.create_callback(_on_rewarded_done)
	mute_callback = JavaScriptBridge.create_callback(_on_mute_change)
	sdk.audio.onMuteChange(mute_callback)
	sdk.loadingFinished()


func gameplay_start() -> void:
	if sdk:
		sdk.gameplayStart()


func gameplay_stop() -> void:
	if sdk:
		sdk.gameplayStop()


func game_end(result: String) -> void:
	if sdk:
		sdk.gameEnd(result)


func commercial_break(done: Callable) -> void:
	if not sdk:
		done.call()
		return
	on_break_done = done
	get_tree().paused = true
	sdk.commercialBreak().then(break_done_callback)


func rewarded_break(done: Callable) -> void:
	if not sdk:
		done.call(false)
		return
	on_rewarded = done
	get_tree().paused = true
	sdk.rewardedBreak().then(rewarded_done_callback)


func _on_break_done(_args: Array) -> void:
	get_tree().paused = false
	on_break_done.call()


func _on_rewarded_done(args: Array) -> void:
	get_tree().paused = false
	on_rewarded.call(args[0].rewarded)


func _on_mute_change(args: Array) -> void:
	AudioServer.set_bus_mute(0, args[0])

Keep each callback in a variable for as long as it may be called. Godot frees a callback that nothing holds, and the SDK then calls nothing.

Set the autoload’s Process Mode to Always, so it still runs while the tree is paused for an ad.

Call it from your game

func start_level() -> void:
	FreeGames.gameplay_start()
	$Level.begin()


func _on_player_died() -> void:
	FreeGames.gameplay_stop()
	FreeGames.game_end("loss")
	$GameOver.show()


func _on_play_again_pressed() -> void:
	FreeGames.commercial_break(start_level)


func _on_watch_ad_pressed() -> void:
	FreeGames.rewarded_break(func(rewarded: bool) -> void:
		if rewarded:
			lives += 1
	)

Both breaks pause the tree until the break is over, then call the function you gave them. With no page around the game (a desktop export, or the editor), they call it at once.

Before you upload

  • Export, then ZIP the contents of the export folder. The HTML file MUST be named index.html: set the export path to index.html.
  • Godot’s web export is large. Check the initial_download number in the Inspector: 20 MB at most.