-
Notifications
You must be signed in to change notification settings - Fork 117
Component
Components are minimal, pure data classes that are plugged into entities to support some behavior. Components give entities data. A component itself implements no behavior.
public class Health extends Component {
public int health;
public int damage;
}Component mappers provide high performance component access and mutation from within a System. Component Mappers are as fast as Transmuters.
class MySystem extends IteratingSystem {
ComponentMapper<Position> mPosition; // You don't need to instance mappers yourself.
}Tip: IntellIJ Live Template for ComponentMapper - Save time!
Adds component to entity, or returns pre-existing.
Position position = mPosition.create(myEntity);
position.x = 10;The component will now be added to the entity (right during the create() call).
Alternatively see #get(myEntity) and getSafe(myEntity,default). Since 2.0.0 #get() will return null for missing components and can safely be used instead of getSafe(myEntity).
Removes component from entity, does nothing if it lacks given component.
mPosition.remove(myEntity);Returns true if part of entity composition.
if ( mPosition.has(myEntity) ) { .. }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)Does your target platform suffer from garbage collection freezes? pool your components!
- Overview
- Concepts
- Getting Started
- Using
- More guides
- Plugins
- Game Gallery
- Tools and Frameworks
- API reference