Skip to main content

Class: Entity

Defined in: ecs/entity.ts:31

Represents an entity in the Entity-Component-System (ECS) architecture. An entity is a container for components and has a unique identifier.

Constructors

Constructor

new Entity(name, world, initialComponents, options): Entity

Defined in: ecs/entity.ts:79

Creates a new Entity instance.

Parameters

name

string

The name of the entity.

world

World

The world to which this entity belongs.

initialComponents

Component[]

The initial components to associate with the entity.

options

Partial<EntityOptions> = {}

Optional configuration for the entity.

Returns

Entity

Properties

enabled

enabled: boolean

Defined in: ecs/entity.ts:40

Indicates whether the entity is enabled.


name

name: string

Defined in: ecs/entity.ts:35

The name of the entity.


world

world: World

Defined in: ecs/entity.ts:45

The world to which this entity belongs.

Accessors

children

Get Signature

get children(): Set<Entity>

Defined in: ecs/entity.ts:155

Gets the child entities of this entity.

Returns

Set<Entity>

A set of child entities.


id

Get Signature

get id(): number

Defined in: ecs/entity.ts:114

Gets the unique identifier of the entity.

Returns

number


parent

Get Signature

get parent(): null | Entity

Defined in: ecs/entity.ts:147

Gets the parent of the entity.

Returns

null | Entity

The parent entity, or null if there is no parent.

Methods

addComponents()

addComponents(...components): void

Defined in: ecs/entity.ts:164

Adds components to the entity.

Parameters

components

...Component[]

The components to add.

Returns

void

Throws

An error if a component with the same name already exists on the entity.


containsAllComponents()

containsAllComponents(query): boolean

Defined in: ecs/entity.ts:182

Checks if the entity contains all specified components.

Parameters

query

Query

The symbols of the components to check.

Returns

boolean

True if the entity contains all specified components, otherwise false.


getComponent()

getComponent<T>(componentName): null | T

Defined in: ecs/entity.ts:197

Gets a component by its name.

Type Parameters

T

T extends Component

Parameters

componentName

symbol

The name of the component to get.

Returns

null | T

The component if found, otherwise null.


getComponentRequired()

getComponentRequired<T>(componentName): T

Defined in: ecs/entity.ts:207

Gets a component by its name.

Type Parameters

T

T extends Component

Parameters

componentName

symbol

The name of the component to get.

Returns

T

The component if found.

Throws

An error if the component is not found.


parentTo()

parentTo(parent): void

Defined in: ecs/entity.ts:122

Sets the parent of the entity.

Parameters

parent

Entity

The parent entity.

Returns

void


removeComponents()

removeComponents(...componentNames): void

Defined in: ecs/entity.ts:223

Removes components from the entity.

Parameters

componentNames

...symbol[]

The name of the components to remove.

Returns

void


removeParent()

removeParent(): void

Defined in: ecs/entity.ts:136

Removes the parent relationship from this entity, if it has one. This will also remove this entity from its parent's set of children. If the entity does not have a parent, this method does nothing.

Returns

void