Skip to content

Fluid Entity Interface

ayslanferreira edited this page Feb 24, 2018 · 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!
  3. Obtain it within your systems, during initialization or world processing cycle!

Obtaining E()

For editing

Pass entityId or entity to E(..).

E(entityId).pos(5,5).angle(10).anim("lion")

Fluid interface directly exposes methods to create, remove, and access and alter components it knows about. Method calls can be chained.

For creation

Omit the id.

E().pos(50,50).entity();

Finish the chain with entity() or id() to obtain a reference to the entity

Using E()

Component lifecycle

given class Pos extends Component {}

Add component

E(id).pos();

Access component

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

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 Pos E::getPos() 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 value) create if true remove if false 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, UNLESS [@Fluid].
anything static, abstract, volatile ignored - -
Clone this wiki locally