-
Notifications
You must be signed in to change notification settings - Fork 112
Component
Components are pure data classes with optionally some helper methods.
All components extend the Component class, which the framework relies on to differentiate them from other classes.
public class Position extends Component {
public float x;
public float y;
public Position(float x, float y) {
this.x = x;
this.y = y;
}
}
public class Health extends Component {
public int health;
public int damage;
public String[] deathSfxId;
public String[] damageSfxId;
public String woundParticle;
public Health(int health) {
this.health = health;
}
}
see Entity how to add and remove components to entities.
Components can be pooled for performance critical environments.
- Small and focused components are easier to reuse.
The advantage of having lightweight components is that it's usually more apparent what a system does by inspecting which components are included by the aspect. If I see a Position component, I know for certain that the system acts on coordinates. Otoh, a Sprite component - containing stuff like rotation, scaling, position, texture, alpha-modulation, size and whatnot - is much harder to tell at a glance what data the system specifically acts on.
- Place game logic into entity systems and managers, never in Components.
- Avoid referencing assets and entities directly.
- Strive for
Serializable
components. It will make a move to persistence or networking a lot easier.
- Overview
- Concepts
- Getting Started
- Using
- More guides
- Plugins
- Game Gallery
- Tools and Frameworks
- API reference