Scene
In the ECS architecture, a Scene is a container for the game world, responsible for managing the lifecycle of entities, systems, and components.
Core Features
Section titled “Core Features”Scene is the core container of the ECS framework, providing:
- Entity creation, management, and destruction
- System registration and execution scheduling
- Component storage and querying
- Event system support
- Performance monitoring and debugging information
Scene Management Options
Section titled “Scene Management Options”ECS Framework provides two scene management approaches:
| Manager | Use Case | Features |
|---|---|---|
| SceneManager | 95% of games | Lightweight, scene transitions |
| WorldManager | MMO servers, room systems | Multi-World, full isolation |
Quick Start
Section titled “Quick Start”Inherit Scene Class
Section titled “Inherit Scene Class”import { Scene, EntitySystem } from '@esengine/ecs-framework';
class GameScene extends Scene { protected initialize(): void { this.name = "GameScene";
// Add systems this.addSystem(new MovementSystem()); this.addSystem(new RenderSystem());
// Create initial entities const player = this.createEntity("Player"); player.addComponent(new Position(400, 300)); player.addComponent(new Health(100)); }
public onStart(): void { console.log("Game scene started"); }
public unload(): void { console.log("Game scene unloaded"); }}Using Scene Configuration
Section titled “Using Scene Configuration”import { ISceneConfig } from '@esengine/ecs-framework';
const config: ISceneConfig = { name: "MainGame", enableEntityDirectUpdate: false};
class ConfiguredScene extends Scene { constructor() { super(config); }}Runtime Environment
Section titled “Runtime Environment”For networked games, you can configure the runtime environment to distinguish between server and client logic.
Global Configuration (Recommended)
Section titled “Global Configuration (Recommended)”Set the runtime environment once at the Core level - all Scenes will inherit this setting:
import { Core } from '@esengine/ecs-framework';
// Method 1: Set in Core.create()Core.create({ runtimeEnvironment: 'server' });
// Method 2: Set static property directlyCore.runtimeEnvironment = 'server';Per-Scene Override
Section titled “Per-Scene Override”Individual scenes can override the global setting:
const clientScene = new Scene({ runtimeEnvironment: 'client' });Environment Types
Section titled “Environment Types”| Environment | Use Case |
|---|---|
'standalone' | Single-player games (default) |
'server' | Game server, authoritative logic |
'client' | Game client, rendering/input |
Checking Environment in Systems
Section titled “Checking Environment in Systems”class CollectibleSpawnSystem extends EntitySystem { private checkCollections(): void { // Skip on client - only server handles authoritative logic if (!this.scene.isServer) return;
// Server-authoritative spawn logic... }}See System Runtime Decorators for decorator-based approach.
Running a Scene
Section titled “Running a Scene”import { Core, SceneManager } from '@esengine/ecs-framework';
Core.create({ debug: true });const sceneManager = Core.services.resolve(SceneManager);sceneManager.setScene(new GameScene());Next Steps
Section titled “Next Steps”- Lifecycle - Scene lifecycle methods
- Entity Management - Create, find, destroy entities
- System Management - System control
- Events - Scene event communication
- Debugging - Performance and debugging
- Best Practices - Scene design patterns