Skip to content
Daan van Yperen edited this page Sep 28, 2015 · 32 revisions

Components are pure data classes with optionally some helper methods.

See Component best practices, Example component.

Components are added/fetched and removed from entities using Component mappers.

In these examples we use ComponentMapper<Position> mPosition;

Add / Get

Adds component to entity, or returns pre-existing.

Position position = mPosition.create(myEntity);
position.x = 10;

Alternatively see #get(myEntity) and getSafe(myEntity[,default]).

Remove

Removes component from entity, does nothing if it lacks given component.

mPosition.remove(myEntity);

Check

Returns true if part of entity composition.

if ( mPosition.has(myEntity) ) { .. }

Toggle

Toggle component. Especially useful for empty tagging components (example: Flaming Invisible etc).

mPosition.set(myEntity,true); // add (if missing)
mPosition.set(myEntity,false); // remove (if exists)

Pooling

Does your target platform suffer from garbage collection freezes? pool your components!

Clone this wiki locally