Skip to content

Fluid Entity Interface

Daan van Yperen edited this page Sep 14, 2016 · 18 revisions

Basic API

Obtain fluid interface

  1. In your systems, statically import com.artemis.E. This exposes E(entityId).
  2. Make sure com.artemis.SuperMapper is one of the first systems in your world!

Usage

Fluid interface directly exposes methods to create, remove, and access and alter components it knows about. Method calls can be chained. E(entityId).pos(5,5).angle(10).anim("monkey").

Component lifecycle

given class Pos extends Component {}

Add component

E(id).pos();

Access component

Pos pos = E(entityId)._pos();

Conventions:

  • Returns null if no component exists.

Remove component

E(id).removePos()

Exposed fields and methods

Access component field

given Anim .. { public Cell cell; }

Example:

Cell cell = E(entityId).animCell();
E(entityId).animCell(cell);

Conventions:

  • This call creates missing components to avoid NPE checks.
  • See internals below for conventions generating field getters/setters.

Access component method

given

class Anim extends Component
{ 
  public Vector getXY() { .. } 
  public void setXY(int x, int y) { .. }  
  public void setXY(Vector v) { .. }  
}

Example:

e = E(Id);
Vector v2 = e.posXY();
e.posXY(5,5).posXY(new Vector(10,10));

Conventions:

  • This call creates missing components to avoid NPE checks.
  • See internals below for conventions generating field getters/setters.

Flag components

Components without public fields and methods are considered flags.

class Invisible extends Component {}

E(id).invisible(false); // remove
E(id).invisible(true); // add
boolean invisible = E(id).isInvisible(true); // invisible?

Call overview

Conventions for components

on component Exposed as if missing comments
Pos E ::pos() create chainable
Pos E ::pos(E e2) mirror e2 chainable
Pos Pos E::_pos() null Getter.
Pos.x int E::posX() create chainable
Pos.x E E::posX(x) create getter
public Pos::set(x,y) E E::pos(x,y) create chainable
public Pos::clear() E E::posClear() create chainable
public Pos::setX(x) E E::posX(x) create chainable
public int Pos::getX() int E::posX() create getter
public Pos::setDepth(z) E E::posDepth(z) create chainable
public float Pos::getDepth() float E::posDepth() create getter
Flag (empty) Invisible E ::invisible(boolean create) see parameter components with no public fields and methods are treated as flags. Additional to E::invisible()
Flag (empty) Invisible E ::isInvisible() - Returns true if has component `false if not.
public int Pos::misc(z) int ::misc(z) - methods with both parameters and return type are exposed as getters.
Clone this wiki locally