Skip to main content

Class: World

Defined in: ecs/world.ts:9

Represents the world in the Entity-Component-System (ECS) architecture. The world manages entities and systems, and updates systems with the entities they operate on.

Implements

Constructors

Constructor

new World(name): World

Defined in: ecs/world.ts:58

Creates a new World instance.

Parameters

name

string

The name of the world.

Returns

World

Properties

name

readonly name: string

Defined in: ecs/world.ts:18

The name of the world.


time

readonly time: Time

Defined in: ecs/world.ts:13

The time instance for the world.

Accessors

entityCount

Get Signature

get entityCount(): number

Defined in: ecs/world.ts:326

Gets the number of entities in the world.

Returns

number

The number of entities.

Methods

addEntities()

addEntities(entities): World

Defined in: ecs/world.ts:284

Adds multiple entities to the world.

Parameters

entities

Entity[]

The entities to add.

Returns

World

The world instance.


addEntity()

addEntity(entity): World

Defined in: ecs/world.ts:237

Adds an entity to the world.

Parameters

entity

Entity

The entity to add.

Returns

World

The world instance.


addSystem()

addSystem(system): World

Defined in: ecs/world.ts:195

Adds a system to the world.

Parameters

system

System

The system to add.

Returns

World

The world instance.


addSystems()

addSystems(...systems): World

Defined in: ecs/world.ts:209

Adds multiple systems to the world.

Parameters

systems

...System[]

The systems to add.

Returns

World

The world instance.


buildAndAddEntity()

buildAndAddEntity(name, components): Entity

Defined in: ecs/world.ts:272

Builds and adds an entity to the world.

Parameters

name

string

The name of the entity.

components

Component[]

The components to add to the entity.

Returns

Entity

The created entity.


onEntitiesChanged()

onEntitiesChanged(callback): void

Defined in: ecs/world.ts:148

Registers a callback to be invoked when entities change.

Parameters

callback

(entities) => void

The callback to register.

Returns

void


onSystemsChanged()

onSystemsChanged(callback): void

Defined in: ecs/world.ts:140

Registers a callback to be invoked when systems change.

Parameters

callback

(systems) => void

The callback to register.

Returns

void


queryEntities()

queryEntities(componentSymbols): Set<Entity>

Defined in: ecs/world.ts:91

Gets all entities in the world that match the given query.

Parameters

componentSymbols

Query

Returns

Set<Entity>

An array of all entities.


queryEntity()

queryEntity(query): null | Entity

Defined in: ecs/world.ts:108

Gets the first entity that matches the given query.

Parameters

query

Query

The query to match against the entities.

Returns

null | Entity

The first matching entity, or null if no entity matches.


queryEntityRequired()

queryEntityRequired(query): Entity

Defined in: ecs/world.ts:124

Gets the first entity that matches the given query, or throws an error if no entity matches.

Parameters

query

Query

The query to match against the entities.

Returns

Entity

The first matching entity.

Throws

An error if no entity matches the query.


raiseOnEntitiesChangedEvent()

raiseOnEntitiesChangedEvent(): void

Defined in: ecs/world.ts:184

Raises the entities changed event.

Returns

void


raiseOnSystemsChangedEvent()

raiseOnSystemsChangedEvent(): void

Defined in: ecs/world.ts:175

Raises the systems changed event.

Returns

void


removeEntity()

removeEntity(entity): World

Defined in: ecs/world.ts:299

Removes an entity from the world.

Parameters

entity

Entity

The entity to remove.

Returns

World

The world instance.


removeOnEntitiesChangedCallback()

removeOnEntitiesChangedCallback(callback): void

Defined in: ecs/world.ts:166

Removes a callback for entities changed events.

Parameters

callback

(entities) => void

The callback to remove.

Returns

void


removeOnSystemsChangedCallback()

removeOnSystemsChangedCallback(callback): void

Defined in: ecs/world.ts:156

Removes a callback for systems changed events.

Parameters

callback

(systems) => void

The callback to remove.

Returns

void


removeSystem()

removeSystem(system): World

Defined in: ecs/world.ts:224

Removes a system from the world.

Parameters

system

System

The system to remove.

Returns

World

The world instance.


stop()

stop(): void

Defined in: ecs/world.ts:314

Stops all systems in the world.

Returns

void

Implementation of

Stoppable.stop


update()

update(deltaTime): void

Defined in: ecs/world.ts:65

Updates the object with the given time.

Parameters

deltaTime

number

Returns

void

Implementation of

Updatable.update


updateSystemEntities()

updateSystemEntities(entity): void

Defined in: ecs/world.ts:250

Updates the entities in the systems based on the components of the given entity.

Parameters

entity

Entity

The entity to update.

Returns

void