Show:
Module: ecs

An entity.

Table of Contents

Constructor

Entity
(
  • idOrUidGenerator=null
  • components=[]
)

Parameters:

  • [idOrUidGenerator=null] Number | UIDGenerator optional

    The entity id if a Number is passed. If an UIDGenerator is passed, the entity will use it to generate a new id. If nothing is passed, the entity will use the default UIDGenerator.

  • [components=[]] ArrayComponent optional

    An array of initial components.

Methods

updateComponent
(
  • name
  • data
)

Update a component field by field, NOT recursively. If the component does not exists, this method create it silently.

Parameters:

  • name String

    Name of the component

  • data Object

    Dict of attributes to update

Example:

entity.addComponent('kite', {vel: 0, pos: {x: 1}}); // entity.component.pos is '{vel: 0, pos: {x: 1}}' entity.updateComponent('kite', {angle: 90, pos: {y: 1}}); // entity.component.pos is '{vel: 0, angle: 90, pos: {y: 1}}'

Properties

components

Object

Components of the entity stored as key-value pairs.

ecs

ECS

A reference to parent ECS class.

id

Number

Unique identifier of the entity.

systems

ArraySystem

Systems applied to the entity.

systemsDirty

Boolean

Indiquate a change in components (a component was removed or added) which require to re-compute entity eligibility to all systems.