| name | phaser-scene-template |
| description | Standardized Phaser scene template with test seam, lifecycle methods, and common patterns. Use when creating new Phaser scenes to ensure consistency, test seam setup, and proper lifecycle management. Provides template code for new scenes. |
Phaser Scene Template
Overview
Standardized Phaser scene template with test seam, lifecycle methods, and common patterns. Accelerate scene creation and ensure consistency.
Template Structure
See assets/scene-template.ts for complete scene template code.
Key Components
- Lifecycle methods:
preload(), create(), update()
- Test seam setup: Standardized test seam structure
- Game state management: Common state patterns
- Scene navigation: Transition methods
Mandatory Test Seam Setup Checklist
Every scene MUST include test seam setup:
Example:
setupTestSeam() {
if (!window.__TEST__) {
window.__TEST__ = {};
}
window.__TEST__.sceneKey = this.scene.key;
window.__TEST__.ready = true;
window.__TEST__.commands = {
goToScene: (key: string) => {
this.scene.start(key);
},
gameState: () => {
return {
scene: this.scene.key,
score: this.score,
};
}
};
}
Test Seam Debugging Patterns
If test seam not working:
- Check if
window.__TEST__ is defined
- Verify scene is initialized (check
create() method)
- Wait for
window.__TEST__.ready === true
- Check scene key matches Phaser scene registration
- Verify commands are defined in
window.__TEST__.commands
Common test seam issues:
- Test seam undefined: Scene not initialized, check
create() method
- Commands not found: Commands not defined in
window.__TEST__.commands
- SceneKey doesn't update: Known issue, use console logs as fallback
- Ready flag false: Scene still initializing, wait for ready
Verification Patterns for Test Seams
Verify test seam setup:
console.log(window.__TEST__);
console.log(window.__TEST__.ready);
console.log(window.__TEST__.sceneKey);
console.log(window.__TEST__.commands);
Test seam command verification:
agent-browser eval "window.__TEST__ && window.__TEST__.ready"
agent-browser eval "window.__TEST__.commands.gameState()"
agent-browser eval "window.__TEST__.commands.goToScene('MainMenu')"
Lifecycle Patterns
See references/lifecycle-patterns.md for detailed lifecycle patterns:
preload() - Load assets
create() - Initialize scene, set up test seam
update() - Game loop
Usage
- Copy
assets/scene-template.ts to your scene file
- Customize for your scene's needs
- Add scene-specific logic
- Update test seam commands
Component Test Scene Variant
When the scene's purpose is to test a single UI component, use the same lifecycle and test seam checklist but with minimal content: only that component plus the test seam. For the full workflow and naming (e.g. ComponentNameTestScene, boot via ?scene=...), use the phaser-component-test-scenes skill.
Resources
assets/scene-template.ts - Template code for new scenes
references/lifecycle-patterns.md - preload, create, update patterns
- phaser-component-test-scenes - Standalone test scenes for UI components (workflow and template)