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

Gets the number of entities in the world.

Returns

number

The number of entities.

Methods

addEntities()

addEntities(entities): this

Defined in: ecs/world.ts:347

Adds multiple entities to the world.

Parameters

entities

Entity[]

The entities to add.

Returns

this

The world instance.


addEntity()

addEntity(entity): this

Defined in: ecs/world.ts:295

Adds an entity to the world.

Parameters

entity

Entity

The entity to add.

Returns

this

The world instance.


addSystem()

addSystem(system, order): this

Defined in: ecs/world.ts:215

Adds a system to the world.

Parameters

system

System

The system to add.

order

number = systemRegistrationPositions.normal

Returns

this

The world instance.


addSystems()

Call Signature

addSystems(order, ...systems): this

Defined in: ecs/world.ts:246

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

Adds multiple systems to the world.

Parameters
systems

...System[]

The systems to add.

Returns

this

The world instance.


buildAndAddEntity()

buildAndAddEntity(name, components, options): Entity

Defined in: ecs/world.ts:331

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.

options

Partial<EntityOptions> = {}

Optional configuration for the entity.

Returns

Entity

The created entity.


getEntityById()

getEntityById(entityId): null | Entity

Defined in: ecs/world.ts:99

Gets the entities in the world with the given entityId.

Parameters

entityId

number

The Id of the entity you would like to get.

Returns

null | Entity

The entity with the matching id, or null if no entity with that id exists.


onEntitiesChanged()

onEntitiesChanged(callback): void

Defined in: ecs/world.ts:166

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

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

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

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

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

Raises the entities changed event.

Returns

void


raiseOnSystemsChangedEvent()

raiseOnSystemsChangedEvent(): void

Defined in: ecs/world.ts:195

Raises the systems changed event.

Returns

void


removeEntity()

removeEntity(entity): this

Defined in: ecs/world.ts:362

Removes an entity from the world.

Parameters

entity

Entity

The entity to remove.

Returns

this

The world instance.


removeOnEntitiesChangedCallback()

removeOnEntitiesChangedCallback(callback): void

Defined in: ecs/world.ts:186

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

Removes a callback for systems changed events.

Parameters

callback

(systems) => void

The callback to remove.

Returns

void


removeSystem()

removeSystem(systemToRemove): this

Defined in: ecs/world.ts:272

Removes a system from the world.

Parameters

systemToRemove

string | System

Returns

this

The world instance.


stop()

stop(): void

Defined in: ecs/world.ts:381

Stops all systems in the world.

Returns

void

Implementation of

Stoppable.stop


update()

update(rawTimeInMilliseconds): void

Defined in: ecs/world.ts:72

Updates the object with the given time.

Parameters

rawTimeInMilliseconds

number

Returns

void

Implementation of

Updatable.update


updateSystemEntities()

updateSystemEntities(entity): void

Defined in: ecs/world.ts:308

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

Parameters

entity

Entity

The entity to update.

Returns

void