Skip to content

Extended Component Mappers

Daan van Yperen edited this page Aug 2, 2015 · 6 revisions

Why?

Easily create and remove components, helps you write shorter code.

   if ( !mPhysics.has(e) ) { e.edit().add(Physics.class); } 
   Physics p = mPhysics.get(e);

becomes

  Physics p = mPhysics.create(e);

Features.

Identical to ComponentMapper, but adds:

  • #create(entity) Creates component, or returns existing.
  • #remove(entity) Removes component, does nothing when already removed.
  • #getSafe(entity,passthrough) Returns component, or passthrough if missing.

Uses Transmuters (bottom of page).

Setup

  WorldConfiguration myConfig = new WorldConfigurationBuilder()
                .with(new ExtendedComponentMapperPlugin())
                .build();
  new World (myConfig);

Wiring

@Wire
public class ExampleSystem extends EntityProcessingSystem {
    protected M<Pos> mPos;
    protected M<Color> mColor;
}