Entity

Entity

new Entity()

Source:

Entity factory.

Methods

addComponent(componentTypeOrComponent, …args) → {Entity}

Source:

Adds new component to entity.

If first argument is component type, component is either created from scratch or reused from pool. In latter case, component's pattern onReuse method is called (if present). Component patterns onCreate method is called with additional arguments passed to add method. If entity is already added to the system (has id greater than 0) addition doesn't happen immediately, but is postponed to nearest update cycle.

Example
// `this` is a reference to Entity instance
// code like this can be seen in entity's `onCreate` method
this.add('Position', 1, 1);

// or

this.add(game.createComponent('Position', 1, 1));
Parameters:
Name Type Attributes Description
componentTypeOrComponent String | Component

component instance or component type

args Any <repeatable>

arguments passed to onCreate method of component

Returns:

Entity instance

Type
Entity

onCreate()

Source:

Called when entity is created. Could be overriden (see EntityStore#register).

onRemove()

Source:

Called when entity is removed. Could be overriden (see EntityStore#register).

onReuse()

Source:

Called when entity is reused from pool. Could be overriden (see EntityStore#register).

removeComponent()

Source:

Removes component.