Scenes
Base class for all game scenes providing the core lifecycle methods for game state management. Forms the foundation of your game’s scene management system.
🏗️ Core Structure
Lifecycle Methods
| Method | Trigger | Purpose |
|---|---|---|
init() | Scene creation | Initial setup 🏗️ |
update(deltaTime) | Every frame | Game logic update 🔄 |
render(ctx) | Every frame | Visual rendering 🎨 |
onMount() | Scene activation | Preparation for display ⬆️ |
onDisMount() | Scene deactivation | Cleanup before hiding ⬇️ |
🧩 Implementation Concept
SelectionScene Example
The SelectionScene demonstrates a typical implementation with:
- UI element management 🖱️
- User selection handling ✅
- Scene transition logic 🔀
Key Features:
- Car selection (model/color) 🚗🎨
- Track selection 🗺️
- Navigation buttons ⏮️⏭️
🏷️ Type Definitions
Scene Transition Flow
graph LR A[StartScene] --> B[SelectionScene] B --> C[GameScene] C --> D[ResultScene]💡 Design Principles
-
Separation of Concerns:
- Each scene handles its own logic
- Clean transitions between states
-
Template Pattern:
- Base class defines structure
- Subclasses implement specifics
-
Lifecycle Management:
- Clear initialization/cleanup
- Predictable update/render cycle
🚀 Pro Tip: Use this system to create modular game sections like menus, levels, and cutscenes!