Skip to content
Ezelia edited this page Jan 9, 2014 · 1 revision

An entity is an instance of eee.Entity. as is, it do nothing, it's juste an object holder with a unique ID.

eee.Entity provide the following methods for entity instances.

in all the bellow code, we suppose we have a component called CPosition witch have x and y properties. see Components wiki page for more information

add(cmp)

add the component cmp to the entity. note that cmp should be an instance. an entity can only hold one instance of each component.

var entity = new eee.Entity();
entity.add(new CPosition(0,0)); //adding CPosition component with x=0 and y=0
entity.add(new CSkin()); //adding CSKin component

we can use chained syntax

var entity = new eee.Entity()
             .add(new CPosition(0,0)) 
             .add(new CSkin());

get(cmpType)

get the component instance of the given type.

if we want to modify the entity position

var pos = entity.get(CPosition); //get the component instance of type CPosition
pos.x = 10;
pos.y += 1;

has(cmpType)

return true if the entity has the component of type cmpType

hasAll(ArrayOfCmpTypes)

return true if the entity has the all the components of types in the array

remove(cmpType)

remove the component of type cmpType note that cmpType should not be an instance but the component type

to remove CSkin component from our entity

entity.remove(CSkin);

destroy()

remove all components, remove the entity reference from all modules, and destroy the entity.

Clone this wiki locally