Skip to content

Scene

In the ECS architecture, a Scene is a container for the game world, responsible for managing the lifecycle of entities, systems, and components.

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

ECS Framework provides two scene management approaches:

ManagerUse CaseFeatures
SceneManager95% of gamesLightweight, scene transitions
WorldManagerMMO servers, room systemsMulti-World, full isolation
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");
}
}
import { ISceneConfig } from '@esengine/ecs-framework';
const config: ISceneConfig = {
name: "MainGame",
enableEntityDirectUpdate: false
};
class ConfiguredScene extends Scene {
constructor() {
super(config);
}
}

For networked games, you can configure the runtime environment to distinguish between server and client logic.

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 directly
Core.runtimeEnvironment = 'server';

Individual scenes can override the global setting:

const clientScene = new Scene({ runtimeEnvironment: 'client' });
EnvironmentUse Case
'standalone'Single-player games (default)
'server'Game server, authoritative logic
'client'Game client, rendering/input
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.

import { Core, SceneManager } from '@esengine/ecs-framework';
Core.create({ debug: true });
const sceneManager = Core.services.resolve(SceneManager);
sceneManager.setScene(new GameScene());