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

### 6. Dual-Rumble Haptics, Analog Steering & Engine Gamepad Wiring (Phaser & Godot) (40 min)
- **Authoritative Source:** [MDN Web Docs · Phaser · Godot Docs](https://developer.mozilla.org/en-US/docs/Web/API/GamepadHapticActuator) — Primary API documentation from Mozilla MDN (GamepadHapticActuator), Phaser Input Docs (https://docs.phaser.io/phaser/concepts/input), and Godot Engine Controllers Guide (https://docs.godotengine.org/en/stable/tutorials/inputs/controllers_gamepads_joysticks.html).
- **Objective:** Trigger PS5 DualSense & Xbox controller vibration (dual-rumble haptics) on hits/boosts, wire analog triggers, and configure native gamepad input in Phaser and Godot HTML5 exports.
- **Key Engineering Rules:**
  - Trigger tactile rumble via `gamepad.vibrationActuator?.playEffect('dual-rumble', { duration: 120, weakMagnitude: 0.4, strongMagnitude: 0.8 })` — always feature-detect so Safari/non-haptic pads fail silently.
  - Use analog trigger pressure (`buttons[7].value` from 0.0 to 1.0) for realistic racing throttle and curved steering response (`Math.sign(x) * Math.pow(Math.abs(x), 1.6)`).
  - In Godot HTML5, bind Joypad Axes & Buttons inside Project Settings → Input Map; in Phaser, enable `input: { gamepad: true }` to support up to 4 local multiplayer Bluetooth controllers.
- **Implementation Steps:**
  1. Review MDN's GamepadHapticActuator docs alongside Phaser's Gamepad input docs and Godot's Controllers & Joysticks guide.
  2. Add a `rumble(intensity, ms)` helper triggered on collisions, drift boosts, and boss hits, gated behind a user Haptics toggle.
  3. Test local 2-player support by iterating all non-null slots in `navigator.getGamepads()` and assigning Player 1 / Player 2 independently.
- **Starter Prompt:** `Upgrade my browser game's Gamepad API layer with feature-detected dual-rumble haptic feedback (vibrationActuator.playEffect) on impacts and boosts, curved analog stick response, analog R2 throttle, and local 2-player controller slot assignment.`
- **Deliverable:** Console-grade PS5/Xbox controller feel with haptics and analog precision in the browser.
