---
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 1 · Beginner: HTML5 Canvas, Game Loops & Your First Browser Game
- **Level:** Beginner · **Price:** 100% Free · **Estimated Time:** 3 hrs
- **Vetted Sources:** MDN Web Docs (Mozilla), Harvard CS50G
- **Outcome:** Build and publish a crisp 60fps HTML5 arcade game with sound, touch support, and a live Spawn Arcade leaderboard.

### 1. Anatomy of a Video Game & requestAnimationFrame Loop (20 min)
- **Authoritative Source:** [MDN Web Docs (Mozilla)](https://developer.mozilla.org/en-US/docs/Games/Anatomy) — Official web platform documentation maintained by Mozilla engineers and W3C contributors.
- **Objective:** Understand how update(), render(), and requestAnimationFrame keep browser games smooth at 60fps without freezing the tab.
- **Key Engineering Rules:**
  - Separate game state update(dt) from canvas draw(ctx) inside requestAnimationFrame.
  - Clamp delta-time (e.g. Math.min(dt, 0.05)) so switching browser tabs never teleports entities.
  - Never run blocking loops or await network calls inside the render loop.
- **Implementation Steps:**
  1. Read MDN's game loop architecture section to see why setInterval drifts while requestAnimationFrame syncs with display refresh.
  2. Structure your game into init(), update(dt), render(), and reset() functions.
  3. Add a clean Game Over state that pauses physics while keeping the restart hotkey responsive.
- **Starter Prompt:** `Create a clean single-file HTML5 Canvas starter using requestAnimationFrame with clamped delta-time (max 50ms), separate update(dt) and render(ctx) functions, and an instant Space/click restart state machine.`
- **Deliverable:** A single-file Canvas loop running smoothly at 60fps with zero tab-switch glitches.

### 2. Build a Complete 2D Arcade Game in Pure JavaScript (40 min)
- **Authoritative Source:** [MDN Web Docs (Mozilla)](https://developer.mozilla.org/en-US/docs/Games/Tutorials/2D_Breakout_game_pure_JavaScript) — The most widely taught, peer-reviewed introductory HTML5 Canvas tutorial on the web.
- **Objective:** Follow the gold-standard MDN step-by-step tutorial to build a complete paddle, ball, brick grid, lives, and score counter from scratch.
- **Key Engineering Rules:**
  - Canvas coordinate system (top-left 0,0), clearRect per frame, and crisp devicePixelRatio scaling.
  - Paddle velocity & reflection angles based on hit offset instead of flat 45-degree bounces.
  - State transitions: Playing → Life Lost → Win / Game Over with score tracking.
- **Implementation Steps:**
  1. Walk through MDN's 10 mini-chapters covering canvas setup, ball movement, wall bounce, paddle input, brick grid, and win/loss states.
  2. Upgrade the visual polish with neon color palettes, particle sparks on brick hits, and combo multipliers.
  3. Export as a standalone index.html and test directly in Spawn Arcade's uploader.
- **Starter Prompt:** `Build a complete single-file HTML5 Canvas 2D Breakout game following MDN best practices: angled paddle rebound, 5-row neon brick grid, 3 lives, combo multiplier, and responsive canvas scaling.`
- **Deliverable:** A playable 2D arcade game with full win/loss loop and score HUD.

### 3. 2D Collision Detection (AABB, Circle & Hitbox Forgiveness) (25 min)
- **Authoritative Source:** [MDN Web Docs (Mozilla)](https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection) — Reference implementation maintained by Mozilla with interactive live code examples.
- **Objective:** Implement reliable rectangle (AABB) and circle collision math—plus the indie secret of slightly forgiving player hitboxes.
- **Key Engineering Rules:**
  - Axis-Aligned Bounding Box (AABB) overlap check for rectangular sprites and platforms.
  - Circle-to-circle distance squared check (dx*dx + dy*dy < (r1+r2)^2) avoids slow Math.sqrt calls.
  - Shrink the player's damage hitbox by 15–20% inside the visual sprite so near-misses feel fair and exciting.
- **Implementation Steps:**
  1. Study MDN's AABB, circle collision, and Separating Axis Theorem overview.
  2. Keep collision checks pure and unit-testable outside your canvas renderer.
  3. Add debug hitbox rendering behind a toggle key (e.g., H) while tuning game feel.
- **Starter Prompt:** `Add pure AABB and circle-vs-circle collision helper functions to my HTML5 game, using a 15% forgiving player hurtbox and a debug hitbox toggle on key 'H'.`
- **Deliverable:** Bug-free collision helpers with unit tests covering edge overlaps and near-misses.

### 4. Zero-Asset Web Audio SFX & Desktop/Mobile Controls (30 min)
- **Authoritative Source:** [MDN Web Docs (Mozilla)](https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Using_Web_Audio_API) — Authoritative W3C Web Audio API & browser input standard documentation.
- **Objective:** Synthesize crisp retro jump, coin, and explosion sounds directly in JavaScript with zero MP3 files, and support keyboard + touch + pointer controls.
- **Key Engineering Rules:**
  - Unlock AudioContext on the first user gesture (click/keydown) to satisfy browser autoplay policies.
  - Synthesize arcade SFX using OscillatorNode + GainNode exponential ramps—zero external asset loading errors.
  - Use Pointer Events (pointerdown/pointermove) + keyboard listeners so desktop and mobile work out of the box.
- **Implementation Steps:**
  1. Review MDN's Web Audio API guide and MDN Control Mechanisms (https://developer.mozilla.org/en-US/docs/Games/Techniques/Control_mechanisms).
  2. Create a tiny sfx.ts helper with playJump(), playCoin(), and playHit() plus a Mute toggle.
  3. Verify touch dragging and tapping inside a narrow mobile viewport.
- **Starter Prompt:** `Add a zero-dependency Web Audio synthesizer (playJump, playScore, playHit, with mute button and first-click AudioContext resume) plus responsive pointer/touch controls so my game works on phones and desktop.`
- **Deliverable:** Synthesized SFX + smooth mobile touch & keyboard input verified on resize.

### 5. Game Design Foundations & Publishing to Spawn Arcade (45 min)
- **Authoritative Source:** [Harvard University CS50G](https://cs50.harvard.edu/games/2018/) — Open-access university game-development course from Harvard University covering Pong, Flappy Bird, Breakout, Match-3, and Mario.
- **Objective:** Learn classic game-design principles from Harvard's open CS50G curriculum and wire the Spawn Arcade SDK to ship your game live.
- **Key Engineering Rules:**
  - Core loop first: make 15 seconds of movement/interaction feel great before adding menus or extra levels.
  - Juice: hit-stop frames, micro screen-shake, easing curves, and particle feedback amplify satisfaction.
  - Wire Spawn Arcade SDK (leaderboard.submit + saves.get/set) via SDK_PROMPT.md before uploading.
- **Implementation Steps:**
  1. Watch CS50G Lectures 0–2 (Pong, Flappy Bird, Breakout) for timeless state-machine and game-feel fundamentals.
  2. Paste Spawn Arcade's SDK_PROMPT.md into your AI coding tool to add global leaderboards and cloud saves.
  3. Drop your finished .html or .zip into /studio/upload and share your live play link.
- **Starter Prompt:** `Polish my HTML5 game with micro screen-shake, particle bursts, and wire Spawn Arcade's browser SDK using https://spawnarcade.com/SDK_PROMPT.md so high scores submit on game over.`
- **Deliverable:** A live published browser game on Spawn Arcade with working leaderboard scores.

---

## 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.

---

## Level 3 · Advanced: Fixed-Timestep Physics, Netcode, GLSL Shaders & WebGPU
- **Level:** Advanced · **Price:** 100% Free · **Estimated Time:** 8 hrs
- **Vetted Sources:** Glenn Fiedler (Gaffer on Games), Gabriel Gambetta, The Book of Shaders, WebGL2 Fundamentals, MDN WebGPU
- **Outcome:** Build silky-smooth multiplayer arenas, custom shader visuals, and commercial-quality web games that rival native Steam indies.

### 1. Deterministic Fixed-Timestep Physics & Interpolation (35 min)
- **Authoritative Source:** [Glenn Fiedler (Gaffer on Games)](https://gafferongames.com/post/fix_your_timestep/) — The most cited physics-loop article in game engineering history, by veteran AAA/network physics engineer Glenn Fiedler.
- **Objective:** Eliminate 60Hz vs 120Hz/144Hz speed bugs and tunneling physics using Glenn Fiedler's canonical accumulator + state interpolation loop.
- **Key Engineering Rules:**
  - Step physics at a fixed `dt` (e.g., 1/60s) inside a `while (accumulator >= dt)` loop.
  - Cap `frameTime` at 0.25s to prevent the 'spiral of death' when a machine lags.
  - Interpolate rendered positions between `previousState` and `currentState` using `alpha = accumulator / dt` for buttery 144Hz visuals.
- **Implementation Steps:**
  1. Read 'Fix Your Timestep!' end-to-end and note the exact accumulator + alpha interpolation pattern.
  2. Upgrade your game loop so physics produces identical trajectories at 30Hz, 60Hz, and 144Hz.
  3. Write a deterministic replay test confirming identical inputs yield identical final coordinates.
- **Starter Prompt:** `Upgrade my game engine to Glenn Fiedler's Fixed-Timestep Accumulator pattern (dt = 1/60, frameTime clamped at 0.25s, alpha render interpolation between prev/curr state) with a determinism test.`
- **Deliverable:** Refresh-rate-independent physics loop verified at 60Hz and 144Hz.

### 2. Fast-Paced Browser Multiplayer: Authoritative Servers & Prediction (60 min)
- **Authoritative Source:** [Gabriel Gambetta](https://www.gabrielgambetta.com/client-server-game-architecture.html) — Renowned four-part multiplayer architecture series by Google Senior Staff Engineer Gabriel Gambetta, complete with interactive lag demos.
- **Objective:** Architect cheat-resistant real-time browser multiplayer with server authority, client-side prediction, server reconciliation, and entity interpolation.
- **Key Engineering Rules:**
  - Never trust client coordinates—send timestamped input commands and simulate authoritatively on the server.
  - Apply Client-Side Prediction locally so controls feel instant even at 120ms ping, then reconcile on server snapshots.
  - Render remote players slightly in the past (Entity Interpolation) for jitter-free motion over WebSockets.
- **Implementation Steps:**
  1. Work through all 4 parts of Gabriel Gambetta's Fast-Paced Multiplayer series.
  2. Keep shared fixed-timestep movement logic in a single TypeScript module imported by both client and WebSocket server.
  3. Test with artificial 150ms latency and 5% packet jitter before shipping.
- **Starter Prompt:** `Design a TypeScript shared-simulation client-server WebSocket protocol implementing Gabriel Gambetta's client-side prediction, input sequence numbers, server reconciliation, and remote entity interpolation.`
- **Deliverable:** Lag-tolerant authoritative multiplayer prototype tested under simulated 150ms latency.

### 3. Custom Visual Juice with GLSL Fragment Shaders (50 min)
- **Authoritative Source:** [The Book of Shaders](https://thebookofshaders.com/) — Acclaimed open interactive shader curriculum by Patricio Gonzalez Vivo and Jen Lowe.
- **Objective:** Write custom GLSL fragment shaders for procedural water, neon glow, dissolve effects, CRT scanlines, and stylized post-processing.
- **Key Engineering Rules:**
  - Fragment shaders execute in parallel per pixel using normalized `uv` coordinates (0.0–1.0) and `u_time`.
  - Use smoothstep(), mix(), and Signed Distance Fields (SDFs) for razor-sharp procedural shapes at any resolution.
  - Apply value/simplex noise to drive fire, water caustics, and hit-dissolve effects with almost zero asset bytes.
- **Implementation Steps:**
  1. Complete Chapters 1–7 of The Book of Shaders (Uniforms, Shaping Functions, Colors, Shapes, Patterns).
  2. Attach a custom ShaderMaterial in Three.js or a fullscreen WebGL quad for a stylized background or hit-flash.
  3. Profile GPU frame time on mobile to avoid heavy multi-octave fragment loops.
- **Starter Prompt:** `Create a reusable Three.js ShaderMaterial implementing a procedural synthwave grid + subtle bloom glow using GLSL SDFs and smoothstep with u_time and u_resolution uniforms.`
- **Deliverable:** Custom GLSL shader effect integrated into a 60fps browser scene.

### 4. Under the Hood of WebGL2 (Buffers, VAOs & Instancing) (50 min)
- **Authoritative Source:** [WebGL2 Fundamentals](https://webgl2fundamentals.org/) — The definitive bottom-up WebGL2 engineering reference maintained by Greggman.
- **Objective:** Understand GPU vertex buffers, attribute pointers, texture atlases, and instanced drawing so you can diagnose any Three.js/Godot bottleneck.
- **Key Engineering Rules:**
  - Batch sprites into a single Texture Atlas so hundreds of entities draw in 1–2 GPU draw calls.
  - Vertex Array Objects (VAOs) and `drawElementsInstanced` slash JS-to-GPU overhead.
  - Handle `webglcontextlost` and `webglcontextrestored` events gracefully.
- **Implementation Steps:**
  1. Read WebGL2 Fundamentals: How It Works, Image Processing, and Instanced Drawing.
  2. Inspect draw-call counts in your Three.js (`renderer.info.render.calls`) or custom WebGL renderer.
  3. Eliminate per-frame buffer allocations inside the render loop.
- **Starter Prompt:** `Audit my WebGL/Three.js renderer for draw-call count and per-frame allocations, batching repeated geometry with instancing and adding clean webglcontextlost recovery.`
- **Deliverable:** Optimized WebGL2 scene maintaining <80 draw calls at 60fps.

### 5. Next-Gen Browser Graphics & Compute Shaders with WebGPU (45 min)
- **Authoritative Source:** [MDN Web Docs (Mozilla)](https://developer.mozilla.org/en-US/docs/Web/API/WebGPU_API) — Official W3C WebGPU API specification guide maintained on MDN Web Docs.
- **Objective:** Explore GPU compute shaders for 100,000-particle simulations and boids flocking in modern browsers using the WebGPU API with WebGL2 fallback.
- **Key Engineering Rules:**
  - Always feature-detect `if ('gpu' in navigator)` and gracefully fall back to WebGL2/Canvas 2D.
  - WGSL compute shaders run parallel particle/flocking physics entirely on the GPU without touching CPU main thread.
  - Pre-compile render pipelines at boot to avoid mid-gameplay shader compilation stutters.
- **Implementation Steps:**
  1. Review MDN's WebGPU API architecture (Adapter → Device → Pipeline → CommandEncoder).
  2. Build a GPU compute-driven particle or boid flock demo with an automatic Canvas/WebGL2 fallback.
  3. Ship your finished game via `npx @playforge/cli deploy` and submit to a Spawn Arcade Vibe Jam.
- **Starter Prompt:** `Create a browser particle/boids demo that uses WebGPU WGSL compute shaders when `navigator.gpu` is available and cleanly falls back to Canvas 2D otherwise.`
- **Deliverable:** Progressive WebGPU demo with clean fallback ready for Spawn Arcade.
