{"skill":{"slug":"game-quality-gates","displayName":"Game Quality Gates","summary":"Game development quality gates and mandatory checks. Activate when building, reviewing, debugging, or deploying any game project (H5/Canvas/WebGL/Phaser/Thre...","description":"---\nname: game-quality-gates\ndescription: Game development quality gates and mandatory checks. Activate when building, reviewing, debugging, or deploying any game project (H5/Canvas/WebGL/Phaser/Three.js/2D/3D). Covers state cleanup, lifecycle management, input handling, audio, persistence, networking, anti-cheat, and performance. Use as pre-deploy checklist or when diagnosing game-specific bugs (state leaks, phantom timers, buff conflicts, memory growth, touch issues).\n---\n\n# Game Quality Gates\n\nMandatory quality standards for all game projects. Based on 70+ real bugs and industry best practices.\n\n## Core Principle\n\n> Bugs come from **cross-state interactions**, not individual features.\n> Each feature works alone; they break in combination.\n\n## 12 Universal Rules (all games)\n\n### 1. Single Cleanup Entry Point 🔄\nAll exit paths (death/level-complete/quit/pause/scene-switch) call ONE cleanup method with options.\n\n```js\ncleanupGameState(opts) {\n  // Fixed order: sub-objects → buffs+timers → UI → projectiles → (optional) enemies/controls/events\n}\n// Every exit: resetBall(), levelComplete(), gameOver(), onShutdown() → calls this\n```\n\n**New feature = add one line here. Never scatter cleanup across exits.**\n\n### 2. Respect Active Buffs ⚡\nAny code modifying attributes (speed/attack/size/defense) must check for active temporary effects first.\n\n```js\n// ❌ speed = Math.max(speed, BASE_SPEED);  // ignores slow buff\n// ✅ speed = Math.max(speed, this._currentBaseSpeed);  // buff-aware baseline\n```\n\n### 3. Cache Before Destroy 📦\nExtract all needed data before `destroy()`/`dispose()`/`remove()`.\n\n```js\nconst { x, y } = obj; const color = obj.getData('color');\nobj.destroy();\nspawnParticles(x, y, color);\n```\n\n### 4. Timers Follow Lifecycle ⏰\nTrack all `setTimeout`/`setInterval`/`delayedCall`/`rAF`. Cancel in cleanup.\n\n```js\nthis.activeTimers.push(this.time.delayedCall(10000, cb));\n// In cleanup: this.activeTimers.forEach(t => t.remove(false));\n```\n\n### 5. Frame-Rate Independent Logic 🖥️\nMultiply all time-dependent logic by delta. Never assume 60fps.\n\n```js\n// ✅ player.x += speed * (delta / 1000);\n```\n- Phaser `update(time, delta)`: delta in ms, divide by 1000\n- Three.js `clock.getDelta()`: returns seconds\n- Physics: prefer fixed timestep (accumulate delta, step every 16.67ms)\n\n### 6. Scene Transition = Full Cleanup 🚪\nOn scene/level switch, clean: event listeners, timers, rAF, audio nodes, object pools, WebGL resources (geometry/material/texture dispose), global state, pending fetch/XHR.\n\nVerify: Chrome DevTools → Memory → heap snapshots before/after transition.\n\n### 7. Audio Lifecycle 🔊\n- iOS: AudioContext must `resume()` inside a user interaction event\n- `visibilitychange` → pause all audio when hidden, resume when visible\n- WeChat WebView: `WeixinJSBridge.invoke('getNetworkType')` before autoplay\n- Pool short sound effects; manage background music separately\n\n### 8. Input Safety 👆\n- Purchase/consume actions: mutex lock + visual disable\n- Attack/fire: cooldown timer\n- State toggles (pause/resume): state machine guard\n- See **Phaser reference** for multi-touch pointer ID tracking\n\n### 9. Save State Persistence 💾\n- Include `version` field for migration when game updates\n- Only persist meaningful state (not particles/temp animations)\n- Auto-save on: level end, manual save, `visibilitychange` (hidden)\n- localStorage limit 5MB; use IndexedDB for larger saves\n- WeChat: use `wx.setStorage` (not localStorage)\n\n### 10. Network Fault Tolerance 🌐\nAll network calls (leaderboard/share/ads/sync): 5s timeout + local cache fallback + no blocking game flow on failure.\n\n### 11. Asset Loading Strategy 📦\nThree tiers: critical (startup, <2s) → level assets (loading screen) → deferred (background lazy load).\nFatal error only for critical failures; degrade gracefully for non-critical.\n\nCompression: GLB+Draco, WebP images, MP3+OGG dual audio, sprite atlases.\n\n### 12. Anti-Cheat Baseline 🛡️\nClient is untrusted. Server validates:\n- One-time raid tokens (bind user+timestamp, single use)\n- Play duration sanity check (can't finish 30 levels in 3 seconds)\n- Score range validation\n- See `references/anti-cheat.md` for implementation patterns\n\n---\n\n## Engine-Specific Rules\n\nFor Phaser-specific rules (pointer ID tracking, physics group cleanup, OVERLAP_BIAS, time vs physics pause):\n→ Read `references/phaser.md`\n\nFor Three.js-specific rules (dispose trio, GLB compression pipeline, animation state machine, prune pitfalls):\n→ Read `references/threejs.md`\n\n---\n\n## Pre-Deploy Checklist\n\nRun this checklist before every deployment:\n\n### 🔴 Universal (all games)\n- [ ] New objects cleaned in `cleanupGameState()`?\n- [ ] New timers cancelled in cleanup?\n- [ ] Attribute changes respect active buffs?\n- [ ] Data cached before destroy?\n- [ ] Movement/animation uses delta time?\n- [ ] No memory leaks across scene transitions? (DevTools verify)\n- [ ] Audio pauses on background/lock?\n- [ ] Purchase/consume has duplicate-click prevention?\n- [ ] Save has version number + migration?\n- [ ] Network calls have timeout + fallback?\n- [ ] Asset load failure has graceful degradation?\n- [ ] Critical operations (spend/settle) server-validated?\n\n### 🟡 Mobile Extra\n- [ ] Multi-touch: each finger tracked independently?\n- [ ] iOS AudioContext resumed after first interaction?\n- [ ] WeChat WebView compatible (no advanced CSS like backdrop-filter)?\n- [ ] Virtual joystick/buttons don't overlap game area?\n- [ ] Orientation change handled?\n\n### 🔵 Engine-specific\n→ See `references/phaser.md` or `references/threejs.md` for engine checklists.\n","topics":["Game","Debugging","Audio","Deploy"],"tags":{"ai-agent":"1.1.0","anti-cheat":"1.1.0","canvas":"1.1.0","game-development":"1.1.0","html5-game":"1.1.0","latest":"1.1.0","openclaw":"1.1.0","phaser":"1.1.0","quality-assurance":"1.1.0","threejs":"1.1.0","webgl":"1.1.0"},"stats":{"comments":0,"downloads":792,"installsAllTime":29,"installsCurrent":3,"stars":0,"versions":2},"createdAt":1772738938276,"updatedAt":1778491738336},"latestVersion":{"version":"1.1.0","createdAt":1772820111836,"changelog":"Added AI Dev Quality Suite cross-references, expanded Related links","license":null},"metadata":null,"owner":{"handle":"abczsl520","userId":"s175k4z16bg51zf0dpm7bya01n885h6s","displayName":"abczsl520","image":"https://avatars.githubusercontent.com/u/65114094?v=4"},"moderation":null}