Skip to content

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

MethodTriggerPurpose
init()Scene creationInitial setup 🏗️
update(deltaTime)Every frameGame logic update 🔄
render(ctx)Every frameVisual rendering 🎨
onMount()Scene activationPreparation for display ⬆️
onDisMount()Scene deactivationCleanup 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

  1. Separation of Concerns:

    • Each scene handles its own logic
    • Clean transitions between states
  2. Template Pattern:

    • Base class defines structure
    • Subclasses implement specifics
  3. Lifecycle Management:

    • Clear initialization/cleanup
    • Predictable update/render cycle

🚀 Pro Tip: Use this system to create modular game sections like menus, levels, and cutscenes!