libgdx Ashley Entity System Creating a Component


Example

Components are simply instances that implement the Ashley component class.

import com.badlogic.ashley.core.Component;
import com.badlogic.ashley.core.ComponentMapper;

public class Position implements Component {
    public static final ComponentMapper<Position> Map = 
                                 ComponentMapper.getFor(Position.class);

    public float x = 0f, 
                 y = 0f;
}

Component maps provide a fast way to access components on entities. Two common ways to manage your component maps is to either keep a static instance within your component's class, or to have a class/enum that contains all the mappers for all your components.

There's no need to declare a mapper for a component type more than once in your application.