# Class: Entity
Simple containers of Components, which give an entity data.
# Table of contents
# Constructors
# Properties
# Methods
- add
- addInternal
- destroy
- get
- getAll
- getComponentBits
- getFamilyBits
- getId
- has
- isScheduledForRemoval
- remove
- removeAll
- removeAllInternal
- removeInternal
- require
# Constructors
# constructor
• new Entity()
# Properties
# flags
• flags: number = 0
A flag that can be used to bit mask this entity. Up to the user to manage.
# Defined in
src/core/Entity.ts:11 (opens new window)
# manager
• Protected manager: null | EntityManager = null
# Defined in
src/core/Entity.ts:25 (opens new window)
# scheduledForRemoval
• Protected scheduledForRemoval: boolean = false
# Defined in
src/core/Entity.ts:15 (opens new window)
# uuid
• Protected uuid: number = 0
# Defined in
src/core/Entity.ts:13 (opens new window)
# Methods
# add
▸ add<T>(component): T
Add a component.
# Type parameters
| Name | Type | Description |
|---|---|---|
T | extends Component<T> | The component class. |
# Parameters
| Name | Type | Description |
|---|---|---|
component | T | The component to add. |
# Returns
T
The added component.
# Defined in
src/core/Entity.ts:49 (opens new window)
# addInternal
▸ Protected addInternal(component): boolean
# Parameters
| Name | Type |
|---|---|
component | Component |
# Returns
boolean
# Defined in
src/core/Entity.ts:111 (opens new window)
# destroy
▸ destroy(): void
Remove this entity from its engine.
# Returns
void
# Defined in
src/core/Entity.ts:38 (opens new window)
# get
▸ get<T>(clazz): undefined | T
Retrieve a Component from this Entity by class.
# Type parameters
| Name | Type | Description |
|---|---|---|
T | extends Component<T> | The component class. |
# Parameters
| Name | Type | Description |
|---|---|---|
clazz | ComponentConstructor<T> | The Component class. |
# Returns
undefined | T
The instance of the specified Component attached to this Entity, or undefined if no such Component exists.
# Defined in
src/core/Entity.ts:84 (opens new window)
# getAll
▸ getAll(): Component[]
# Returns
A list with all the Components of this Entity.
# Defined in
src/core/Entity.ts:73 (opens new window)
# getComponentBits
▸ getComponentBits(): ReadonlyBits
# Returns
This Entity's Component bits, describing all the Components it contains.
# Defined in
src/core/Entity.ts:150 (opens new window)
# getFamilyBits
▸ getFamilyBits(): ReadonlyBits
# Returns
This Entity's Family bits, describing all the Families it belongs to.
# Defined in
src/core/Entity.ts:155 (opens new window)
# getId
▸ getId(): number
# Returns
number
The Entity's unique id.
# Defined in
src/core/Entity.ts:28 (opens new window)
# has
▸ has(clazz): boolean
# Parameters
| Name | Type | Description |
|---|---|---|
clazz | ComponentConstructor<Component> | The Component class. |
# Returns
boolean
Whether or not the Entity has a Component for the specified class.
# Defined in
src/core/Entity.ts:106 (opens new window)
# isScheduledForRemoval
▸ isScheduledForRemoval(): boolean
# Returns
boolean
True if the entity is scheduled to be removed.
# Defined in
src/core/Entity.ts:33 (opens new window)
# remove
▸ remove(clazz): void
Removes the Component of the specified type. Since there is only ever one Component of one type, we don't need an instance reference.
# Parameters
| Name | Type | Description |
|---|---|---|
clazz | ComponentConstructor<Component> | The Component class. |
# Returns
void
# Defined in
src/core/Entity.ts:61 (opens new window)
# removeAll
▸ removeAll(): void
Removes all the Components from the Entity.
# Returns
void
# Defined in
src/core/Entity.ts:67 (opens new window)
# removeAllInternal
▸ Protected removeAllInternal(): boolean
# Returns
boolean
# Defined in
src/core/Entity.ts:139 (opens new window)
# removeInternal
▸ Protected removeInternal(clazz): undefined | Component
# Parameters
| Name | Type |
|---|---|
clazz | ComponentConstructor<Component> |
# Returns
undefined | Component
# Defined in
src/core/Entity.ts:126 (opens new window)
# require
▸ require<T>(clazz): T
Require a Component from this Entity by class.
throws If the component doesn't exist on this entity.
# Type parameters
| Name | Type | Description |
|---|---|---|
T | extends Component<T> | The component class. |
# Parameters
| Name | Type | Description |
|---|---|---|
clazz | ComponentConstructor<T> | The Component class. |
# Returns
T
The instance of the specified Component attached to this Entity.
# Defined in
← Engine EntityFactory →