Constructor
new Entity(name)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
name |
string | Entity |
Members
alive :boolean
Type:
- boolean
components :Array.<Component>
Type:
- Array.<Component>
index :number|null
Type:
- number | null
name :string
Type:
- string
remove :boolean
Type:
- boolean
Methods
addComponent(component) → {Entity}
Add a Component to the entity
Parameters:
Name | Type | Description |
---|---|---|
component |
Component |
Returns:
- Type
- Entity
addListener(event, callback) → {Entity}
Add eventlistener to entity
Parameters:
Name | Type | Description |
---|---|---|
event |
string | |
callback |
function |
Returns:
- Type
- Entity
destroy()
Kills the entity
emit(event, data) → {Entity}
Emit event with data
Parameters:
Name | Type | Description |
---|---|---|
event |
string | |
data |
object |
Returns:
- Type
- Entity
getAllComponents() → {Array.<Component>}
Get all components from the entity
Returns:
- Type
- Array.<Component>
getComponent(component) → {Component}
Get a Component from the entity
Parameters:
Name | Type | Description |
---|---|---|
component |
function | component constructor |
Throws:
Error
Returns:
- Type
- Component
getComponents(component) → {Array.<Component>}
Get all mathing components
Parameters:
Name | Type | Description |
---|---|---|
component |
function | component constructor |
Returns:
- Type
- Array.<Component>
getIndex() → {number|null}
Get index of entity
Returns:
- Type
- number | null
hasComponent(component) → {boolean}
Get a Component from the entity by its tag name
Parameters:
Name | Type | Description |
---|---|---|
component |
function |
Returns:
- Type
- boolean
isAlive() → {boolean}
Check if entity is alive
Returns:
- Type
- boolean
isRemove() → {boolean}
Check if entity should be removed in next cycle
Returns:
- Type
- boolean
removeComponent(component) → {Entity}
remove a Component from the entity
Parameters:
Name | Type | Description |
---|---|---|
component |
function |
Returns:
- Type
- Entity
removeListener(event) → {Entity}
Remove event listener
Parameters:
Name | Type | Description |
---|---|---|
event |
string |
Returns:
- Type
- Entity
setIndex(index)
Set index value of entity
Parameters:
Name | Type | Description |
---|---|---|
index |
number |