Web games
A web game is a build whose archive has an index.html at its root. Spawnle
installs it like any other game and runs it in the player’s browser.
How the launcher serves your game
Section titled “How the launcher serves your game”The launcher does not open your game from file://. It serves the game’s
folder on its own local address:
http://127.0.0.1:<port>/- Each game always gets the same port, so its origin is stable:
localStorage, IndexedDB and cookies survive between sessions, exactly like on a website. fetch(), ES modules, Web Workers and WebAssembly all work, because the page has a real origin.- Pages are served with
Cross-Origin-Opener-Policy: same-originandCross-Origin-Embedder-Policy: credentialless, soSharedArrayBufferis available (Godot 4’s web export needs it) while scripts and images from CDNs still load. - Only files inside your game’s folder are served, only to this computer.
/__spawnle/sdk.jsis the JavaScript SDK bundled with the launcher.
The ticket in the URL
Section titled “The ticket in the URL”The launcher opens your game with the session in the URL fragment:
http://127.0.0.1:41234/#spawnle_ticket=gt_…&spawnle_api=https%3A%2F%2Fapi.spawnle.com&spawnle_game=neon-moth| Parameter | Meaning |
|---|---|
spawnle_ticket |
The player’s game ticket. |
spawnle_api |
The API to call (https://api.spawnle.com). |
spawnle_game |
Your game’s id. |
Fragments never reach any server — not even the local one. Spawnle.init()
reads them, keeps them in sessionStorage (so a reload keeps the session)
and removes them from the address bar. If you do not use the SDK, do the same.
Engines
Section titled “Engines”The SDK is a single script with no dependencies, so it works with any engine that exports to the web.
Phaser, PixiJS, Three.js, Babylon.js, plain canvas
Section titled “Phaser, PixiJS, Three.js, Babylon.js, plain canvas”Load spawnle.js before your game and call await Spawnle.init() while your
loading screen is up.
Godot 4
Section titled “Godot 4”Call the SDK through JavaScriptBridge:
var spawnle
func _ready(): var window = JavaScriptBridge.get_interface("window") var promise = window.Spawnle.init() promise.then(JavaScriptBridge.create_callback(_on_ready))
func _on_ready(args): spawnle = args[0] $Name.text = str(spawnle.user.displayName)Add <script src="spawnle.js"></script> to your export’s Head include
and copy spawnle.js next to the exported index.html.
Unity (WebGL)
Section titled “Unity (WebGL)”Write a small .jslib plugin that calls the SDK, and call it from C# with
[DllImport("__Internal")]. Native Unity builds use the
REST API instead.
Local mode
Section titled “Local mode”Opened any other way — your dev server, file://, itch.io — init() runs in
local mode: a stand-in player called “Local player” (rename it with
localPlayer: { name }), saves, unlocked achievements and best scores in
localStorage, and leaderboards with only that player. Your game never has
to special-case it.
Local mode does not know your achievement definitions, so any key unlocks and
achievements.list() returns only what was unlocked. Limits are not enforced
either: test those inside Spawnle.
To require Spawnle (for a multiplayer game, say), pass requireSpawnle: true;
init() then rejects with the error code no_ticket.
const spawnle = await Spawnle.init({ requireSpawnle: true });