Skip to content

Class: Entity

Entity is one of the key elements of the Entity-Component-System architecture. Entity is just to tie components together, and to give Systems ways to group and link components. The entity is basically just an ID, with some meta information of tags and layers for grouping and filtering, alongside some helper functions for adding/removing components and destroying itself.

Implements

Table of contents

Constructors

Properties

Methods

Constructors

constructor

+ new Entity(messageBus: IMessageBus, tags?: string[], layers?: string[], id?: number): Entity

Parameters:

Name Type
messageBus IMessageBus
tags string[]
layers string[]
id number

Returns: Entity

Properties

id

id: number

Unique numeric identifier of the entity.

Implementation of: IEntity.id


layers

layers: string[]

A list of layers the entity belongs to, used for grouping entities.

Implementation of: IEntity.layers


tags

tags: string[]

A list of tags the entity has, used for discriminating between entities without having to add custom components.

Implementation of: IEntity.tags


MESSAGE_DESTROY

Readonly Static MESSAGE_DESTROY: entity_destroy= "entity_destroy"

Message broadcast when an entity is destroyed.

Methods

Add

Add(component: Component): void

Add adds a component to the entity.

Parameters:

Name Type
component Component

Returns: void


Destroy

Destroy(): void

Destroy deletes the entity and all associated components.

Returns: void


Remove

Remove(key: string): void

Remove removes a component from the entity.

Parameters:

Name Type
key string

Returns: void