Class: Entity

Entity(name)

An entity is a object that holds many components. Those components define the behaviour of an entity.

Constructor

new Entity(name)

Parameters:
Name Type Default Description
name string Entity
Source:

Members

alive :boolean

Type:
  • boolean
Source:

components :Array.<Component>

Type:
Source:

index :number|null

Type:
  • number | null
Source:

name :string

Type:
  • string
Source:

remove :boolean

Type:
  • boolean
Source:

Methods

addComponent(component) → {Entity}

Add a Component to the entity
Parameters:
Name Type Description
component Component
Source:
Returns:
Type
Entity

addListener(event, callback) → {Entity}

Add eventlistener to entity
Parameters:
Name Type Description
event string
callback function
Source:
Returns:
Type
Entity

destroy()

Kills the entity
Source:

emit(event, data) → {Entity}

Emit event with data
Parameters:
Name Type Description
event string
data object
Source:
Returns:
Type
Entity

getAllComponents() → {Array.<Component>}

Get all components from the entity
Source:
Returns:
Type
Array.<Component>

getComponent(component) → {Component}

Get a Component from the entity
Parameters:
Name Type Description
component function component constructor
Source:
Throws:
Error
Returns:
Type
Component

getComponents(component) → {Array.<Component>}

Get all mathing components
Parameters:
Name Type Description
component function component constructor
Source:
Returns:
Type
Array.<Component>

getIndex() → {number|null}

Get index of entity
Source:
Returns:
Type
number | null

hasComponent(component) → {boolean}

Get a Component from the entity by its tag name
Parameters:
Name Type Description
component function
Source:
Returns:
Type
boolean

isAlive() → {boolean}

Check if entity is alive
Source:
Returns:
Type
boolean

isRemove() → {boolean}

Check if entity should be removed in next cycle
Source:
Returns:
Type
boolean

removeComponent(component) → {Entity}

remove a Component from the entity
Parameters:
Name Type Description
component function
Source:
Returns:
Type
Entity

removeListener(event) → {Entity}

Remove event listener
Parameters:
Name Type Description
event string
Source:
Returns:
Type
Entity

setIndex(index)

Set index value of entity
Parameters:
Name Type Description
index number
Source: