Standardized patterns for testing Phaser game movement, including key state handling and collision verification. Use when testing player movement, collision detection, or when movement testing challenges occur. Phaser requires keydown/keyup pattern, not single press events.
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Um comando direto ignora o prompt de revisão. Verifique a origem antes de executá-lo.
Standardized patterns for testing Phaser game movement, including key state handling and collision verification. Use when testing player movement, collision detection, or when movement testing challenges occur. Phaser requires keydown/keyup pattern, not single press events.
Phaser Movement Testing
Overview
Standardize Phaser movement testing patterns. Phaser uses continuous key state checking, not discrete events.
Key Input Pattern
Phaser requires keydown/keyup pattern, not single press events
Pattern:
keydown ArrowRight
sleep 0.5
keyup ArrowRight
Why: Phaser checks key state continuously in update() loop, not on single events.
See references/key-input.md for detailed key input patterns.
Common Pitfalls: Browser Automation Limitations
CRITICAL: Browser automation keydown/keyup events don't work reliably with Phaser's input system.
Why Browser Automation Fails
Problem: Phaser's input system requires native browser events, but browser automation tools (agent-browser, Playwright, Puppeteer) generate synthetic events that Phaser doesn't recognize.
Observed Issue: Browser automation keydown/keyup commands don't trigger Phaser's key listeners, causing movement tests to fail.
Root Cause:
Phaser checks key.isDown property in update() loop
Browser automation generates synthetic events
Phaser's input system doesn't recognize synthetic events
Native browser events are required for Phaser input
Workaround Patterns
When browser automation fails, use these workaround patterns:
Direct Key Object Manipulation (Preferred)
Programmatic Movement Simulation (Alternative)
Test Seam Commands (Best Practice)
Direct Key Object Manipulation
Manipulate Phaser key objects directly when browser automation doesn't work.
Pattern 1: Direct Key State Setting
Set key.isDown property directly:
// In test seam or browser evalwindow.__TEST__.commands.simulateKeyPress = (keyCode: string) => {
const scene = window.__TEST__?.getCurrentScene();
if (!scene) returnfalse;
// Get Phaser key objectconst key = scene.input.keyboard?.addKey(keyCode);
if (!key) returnfalse;
// Set key state directly
key.isDown = true;
key.isUp = false;
// Trigger update loop to process movement
scene.update(0, 0);
returntrue;
};
window.__TEST__.commands.simulateKeyRelease = (keyCode: string) => {
const scene = window.__TEST__?.getCurrentScene();
if (!scene) returnfalse;
const key = scene.input.keyboard?.addKey(keyCode);
if (!key) returnfalse;
// Release key state
key.isDown = false;
key.isUp = true;
returntrue;
};
# Test movement in all directions
agent-browser eval"window.__TEST__.commands.testMovement('right')"
agent-browser eval"window.__TEST__.commands.testMovement('left')"
agent-browser eval"window.__TEST__.commands.testMovement('up')"
agent-browser eval"window.__TEST__.commands.testMovement('down')"
Common Pitfalls and Solutions
Pitfall 1: Browser Automation Key Events Don't Work