Skip to main content

Class: World

Defined in: ecs/world.ts:16

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:65

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:25

The name of the world.


time

readonly time: Time

Defined in: ecs/world.ts:20

The time instance for the world.

Accessors

entityCount

Get Signature

get entityCount(): number

Defined in: ecs/world.ts:367

Gets the number of entities in the world.

Returns

number

The number of entities.

Methods

addEntities()

addEntities(entities): World

Defined in: ecs/world.ts:325

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:278

Adds an entity to the world.

Parameters

entity

Entity

The entity to add.

Returns

World

The world instance.


addSystem()

addSystem(system, order): World

Defined in: ecs/world.ts:202

Adds a system to the world.

Parameters

system

System

The system to add.

order

number = systemRegistrationPositions.normal

Returns

World

The world instance.


addSystems()

Call Signature

addSystems(order, ...systems): this

Defined in: ecs/world.ts:227

Adds multiple systems to the world.

Parameters
order

number

systems

...System[]

The systems to add.

Returns

this

The world instance.

Call Signature

addSystems(...systems): this

Defined in: ecs/world.ts:228

Adds multiple systems to the world.

Parameters
systems

...System[]

The systems to add.

Returns

this

The world instance.


buildAndAddEntity()

buildAndAddEntity(name, components): Entity

Defined in: ecs/world.ts:313

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:155

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:147

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:98

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:115

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:131

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:191

Raises the entities changed event.

Returns

void


raiseOnSystemsChangedEvent()

raiseOnSystemsChangedEvent(): void

Defined in: ecs/world.ts:182

Raises the systems changed event.

Returns

void


removeEntity()

removeEntity(entity): World

Defined in: ecs/world.ts:340

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:173

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:163

Removes a callback for systems changed events.

Parameters

callback

(systems) => void

The callback to remove.

Returns

void


removeSystem()

removeSystem(systemToRemove): World

Defined in: ecs/world.ts:255

Removes a system from the world.

Parameters

systemToRemove

string | System

Returns

World

The world instance.


stop()

stop(): void

Defined in: ecs/world.ts:355

Stops all systems in the world.

Returns

void

Implementation of

Stoppable.stop


update()

update(deltaTime): void

Defined in: ecs/world.ts:72

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:291

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

Parameters

entity

Entity

The entity to update.

Returns

void