---
name: spawn-arcade-gamedev
description: Complete Beginner-to-Advanced browser game engineering curriculum, vetted primary sources, architecture rules, and Spawn Arcade SDK/publishing standards.
source: https://spawnarcade.com/learn
---

# Spawn Arcade — Browser Game Development Mastery Skill

Use this knowledge pack whenever building, polishing, testing, or publishing an HTML5, Canvas 2D, Phaser 3, Three.js, WebGL2, WebGPU, or Godot HTML5 browser game for **Spawn Arcade** (`https://spawnarcade.com`).

## Non-Negotiable Engineering & Publishing Rules
1. **60fps Clean Loop:** Use `requestAnimationFrame` with clamped delta-time (`Math.min(dt, 0.05)`) or Glenn Fiedler's fixed-timestep accumulator (`dt = 1/60`). Never await network calls in the render loop.
2. **Zero-Friction Start:** Level 1 / core gameplay must be playable immediately on load with keyboard + mouse/touch controls and instant restart.
3. **Relative Asset Paths:** Always use relative paths (`./assets/...`, Vite `base: './'`) so builds run cleanly on isolated `*.spawnarcade.app` subdomains.
4. **Sandbox-Safe Storage & Audio:** Wrap `localStorage` calls in try/catch with in-memory fallback (for opaque preview frames) and resume Web Audio `AudioContext` on the first user gesture.
5. **Spawn Arcade SDK Integration:** Wire `window.playforge` (`auth.getPlayer`, `saves.get/set`, `leaderboard.submit/top`, `commerce.isUnlocked/requestUnlock/openTipJar`) using `https://spawnarcade.com/SDK_PROMPT.md`.
6. **Security & Bundle Hygiene:** Keep builds self-contained (no external untrusted script CDNs, no `window.top.location`, no `<input type="password">`), and pass `playforge check` before publishing.
## Level 2 · Intermediate: Phaser, Three.js 3D, Godot HTML5 & Game Architecture
- **Level:** Intermediate · **Price:** 100% Free · **Estimated Time:** 6 hrs
- **Vetted Sources:** Phaser Official, Three.js Manual, Godot Foundation, Bob Nystrom, Red Blob Games
- **Outcome:** Ship commercial-grade 2D/3D browser games with modular architecture, clean AI-friendly repos, and Free-Demo-to-Paid-Unlock funnels.

### 1. Multi-Scene 2D Games with Phaser 3 (45 min)
- **Authoritative Source:** [Phaser Official Docs](https://phaser.io/tutorials/making-your-first-phaser-3-game) — Official tutorial from Photon Storm, creators of the industry-standard HTML5 2D game framework.
- **Objective:** Use Phaser 3's official tutorial to build tilemaps, sprite animations, Arcade Physics, and Boot/Menu/Play/GameOver scenes.
- **Key Engineering Rules:**
  - Split games into explicit Phaser Scenes (PreloadScene, MenuScene, GameScene, HudScene).
  - Use Arcade Physics groups and colliders instead of hand-rolling platformer gravity bugs.
  - Keep Vite bundle paths relative (`base: './'`) so ZIP uploads run cleanly from any sandbox URL.
- **Implementation Steps:**
  1. Complete Phaser's official 10-part platformer tutorial (sprites, physics bodies, star pickups, bombs).
  2. Configure Vite with `base: './'` so all sprite sheets resolve inside Spawn Arcade's isolated sandbox.
  3. Run `playforge check dist` to confirm bundle size and relative asset paths.
- **Starter Prompt:** `Scaffold a Vite + TypeScript + Phaser 3 game with BootScene, GameScene, and HudScene, configured with `base: './'` so `dist/` deploys cleanly as a static ZIP bundle.`
- **Deliverable:** A bundled multi-scene Phaser 3 game passing `playforge check`.

### 2. 3D Browser Games with Three.js & WebGL (55 min)
- **Authoritative Source:** [Three.js Official Manual](https://threejs.org/manual/#en/fundamentals) — Official Three.js Manual authored by Greggman and the Three.js core maintainers.
- **Objective:** Build 60fps 3D browser scenes with cameras, lighting, instanced meshes, and low-poly performance budgets.
- **Key Engineering Rules:**
  - Always cap `renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))` so retina displays stay 60fps.
  - Use InstancedMesh and shared Geometries/Materials to keep draw calls under 100 on mobile WebGL.
  - Dispose geometries/textures on level transitions to prevent WebGL context loss and memory leaks.
- **Implementation Steps:**
  1. Study Three.js Fundamentals and Responsive Design in the official manual.
  2. Decouple your 3D physics/simulation state (`src/sim/`) from the Three.js mesh layer (`src/render/`).
  3. Compress `.glb` models with Draco/Meshopt to keep the total build under 50 MB.
- **Starter Prompt:** `Build a Vite + TypeScript + Three.js 3D browser game with decoupled simulation and renderer modules, InstancedMesh props, pixelRatio capped at 2, and full resize handling.`
- **Deliverable:** A 60fps Three.js 3D game running cleanly on desktop and mobile browsers.

### 3. Building in Godot 4 & Exporting Cleanly for the Web (50 min)
- **Authoritative Source:** [Godot Engine Official Docs](https://docs.godotengine.org/en/stable/tutorials/export/exporting_for_web.html) — Official documentation maintained by the Godot Foundation engineering team.
- **Objective:** Follow Godot's official 2D game guide and Web Export checklist (Compatibility renderer, single-threaded vs COOP/COEP threads, .pck sizing).
- **Key Engineering Rules:**
  - Select the Compatibility (GLES3/WebGL2) renderer for maximum browser & Safari compatibility.
  - Prefer single-threaded Web export unless you need SharedArrayBuffer; Spawn Arcade auto-enables COOP/COEP + CORP headers when detected.
  - Bridge Godot GDScript to Spawn Arcade's JS SDK using `JavaScriptBridge.eval(...)`.
- **Implementation Steps:**
  1. If new to Godot, complete Godot's official 'Your First 2D Game' (https://docs.godotengine.org/en/stable/getting_started/first_2d_game/index.html).
  2. Configure the Web export preset with `index.html` as the root filename.
  3. Zip the export directory and verify COOP/COEP detection with `playforge check`.
- **Starter Prompt:** `Write a Godot 4 GDScript wrapper class `SpawnArcadeBridge.gd` using `JavaScriptBridge` that safely calls `window.playforge.leaderboard.submit` and `window.playforge.commerce.isUnlocked` when running on the web.`
- **Deliverable:** A Godot 4 HTML5 export ZIP verified for browser play.

### 4. Game Architecture Patterns That Keep AI Agents Productive (45 min)
- **Authoritative Source:** [Game Programming Patterns (Bob Nystrom)](https://gameprogrammingpatterns.com/contents.html) — Industry-classic free online book by former Electronic Arts & Google Dart engineer Bob Nystrom.
- **Objective:** Apply Bob Nystrom's classic Game Loop, State Machine, Component, and Object Pool patterns so AI coding tools never tangle your codebase.
- **Key Engineering Rules:**
  - Finite State Machines (Title → Playing → Paused → GameOver) eliminate boolean flag soup.
  - Object Pools reuse bullets and particles to avoid garbage-collection stutter frames.
  - Data-driven configs (JSON tables for enemies, levels, upgrades) let AI agents balance gameplay safely.
- **Implementation Steps:**
  1. Read the Game Loop, State, and Object Pool chapters in Game Programming Patterns.
  2. Refactor monolithic single-file prototypes into `sim/`, `render/`, `audio/`, and `data/` folders.
  3. Write fast Vitest unit tests against pure `sim/` functions so AI edits are regression-checked.
- **Starter Prompt:** `Refactor this browser game using Bob Nystrom's Game Programming Patterns: explicit Finite State Machine, preallocated Object Pool for particles/projectiles, and pure unit-tested simulation logic.`
- **Deliverable:** Modular game repo with pure simulation unit tests passing in Vitest.

### 5. Interactive AI Pathfinding (A*) & Tactical Grids (40 min)
- **Authoritative Source:** [Red Blob Games (Amit Patel)](https://www.redblobgames.com/pathfinding/a-star/introduction.html) — Widely regarded as the clearest interactive CS & game-math visual reference on the internet, by Stanford CS alumnus Amit Patel.
- **Objective:** Master grid movement, breadth-first search, A* pathfinding, and hexagonal coordinates for strategy, RPG, and tower-defense games.
- **Key Engineering Rules:**
  - A* combines actual cost-so-far g(n) with heuristic distance h(n) (Manhattan for 4-way grids, Octile for 8-way).
  - Precompute a single Flow Field (BFS from goal) when 50+ tower-defense enemies share one target.
  - For hex grids, use axial/cube coordinates (q, r, s where q+r+s=0) for clean distance and neighbor math.
- **Implementation Steps:**
  1. Interact with Red Blob Games' A* visualizer and Hexagonal Grids guide (https://www.redblobgames.com/grids/hexagons/).
  2. Implement a deterministic `findPath(grid, start, goal)` function with unit tests for blocked walls and no-path cases.
  3. Wire enemy telegraphing so players can read AI moves one turn ahead.
- **Starter Prompt:** `Implement a deterministic A* pathfinding module (with priority queue, wall avoidance, and Manhattan heuristic) plus Vitest tests, inspired by Red Blob Games.`
- **Deliverable:** Tested pathfinding module powering intelligent enemies in a strategy or TD game.

### 6. Connect PS5 DualSense, Xbox & Bluetooth Controllers (Web Gamepad API) (35 min)
- **Authoritative Source:** [MDN Web Docs (Mozilla)](https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API/Using_the_Gamepad_API) — Official Mozilla MDN & W3C Gamepad API specification guide (https://w3c.github.io/gamepad/) covering standard controller layouts across Chrome, Edge, Safari, and Firefox.
- **Objective:** Add zero-driver Bluetooth & USB controller support for PS5 DualSense, Xbox Wireless, and Switch Pro controllers using the standard browser Gamepad API.
- **Key Engineering Rules:**
  - Pair PS5 DualSense (hold Create + PS until light bar flashes) or Xbox Wireless (hold Pair button) via macOS, Windows, iOS, or Android Bluetooth — browsers detect them automatically with zero installs.
  - Poll `navigator.getGamepads()` inside `requestAnimationFrame` (Chrome requires polling fresh snapshots every frame) and apply a 0.15–0.20 analog stick deadzone to stop drift.
  - Use W3C Standard Mapping: Left Stick = `axes[0..1]`, Right Stick = `axes[2..3]`, Cross/A = `buttons[0]`, Circle/B = `buttons[1]`, Triggers L2/R2 = `buttons[6..7]` (analog `.value`), Start/Options = `buttons[9]`, D-Pad = `buttons[12..15]`.
- **Implementation Steps:**
  1. Read MDN's Using the Gamepad API guide and inspect the W3C Standard Gamepad button diagram (https://w3c.github.io/gamepad/).
  2. Listen to `gamepadconnected` / `gamepaddisconnected` to display a live 'Controller Connected' HUD badge and swap button prompts (Cross/A instead of Space).
  3. Build a unified `readInput()` helper that blends keyboard, touch, and `navigator.getGamepads()` so every player gets smooth analog steering and instant pause on Start/Options.
- **Starter Prompt:** `Add plug-and-play PS5 DualSense and Xbox Bluetooth controller support using the HTML5 Web Gamepad API: poll navigator.getGamepads() inside requestAnimationFrame, map left stick (with 0.18 deadzone) and D-Pad to movement, Cross/A to jump/action, R2/Circle/B to boost, Options/Start to pause, and show a subtle 'Controller Connected' HUD pill.`
- **Deliverable:** Unified keyboard + Bluetooth PS5/Xbox controller input module running smoothly in any browser.
