Class: ComponentManager
ComponentManager holds a map/record of components of the same type, mapped to the ID of the entity the component belongs to. Used in conjunction with the EntityManager for managing Entities/Components.
Table of contents
Constructors
Properties
Methods
Constructors
constructor
+ new ComponentManager(key
: string, components?
: Map<number, Component>): ComponentManager
Parameters:
Name | Type |
---|---|
key |
string |
components |
Map<number, Component> |
Returns: ComponentManager
Properties
key
• key: string
Methods
Add
▸ Add(entity
: IEntity, component
: Component): void
Add adds a component to the ComponentManager, mapped to the entity that the component belongs to.
Parameters:
Name | Type | Description |
---|---|---|
entity |
IEntity | Entity of the component to add |
component |
Component | Component to add |
Returns: void
Get
▸ Get(entity
: IEntity): undefined | Component
Get returns a component associated with an entity if it exists, otherwise returns undefined.
Parameters:
Name | Type | Description |
---|---|---|
entity |
IEntity | Entity to get the component of |
Returns: undefined | Component
Component retrieved, if doesn't exist, undefined
Remove
▸ Remove(entity
: IEntity): void
Remove removes a component from the ComponentManager if it exists.
Parameters:
Name | Type | Description |
---|---|---|
entity |
IEntity | Entity of the component to remove |
Returns: void