-
Notifications
You must be signed in to change notification settings - Fork 112
Component
DaanVanYperen edited this page Sep 19, 2014
·
32 revisions
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 implements Serializable {
public float x;
public float y;
public Pos(float x, float y) {
this.x = x;
this.y = y;
}
}
public class Health extends Component implements Serializable {
public int health;
public int damage;
public String[] deathSfxId;
public String[] damageSfxId;
public String woundParticle;
public Health(int health) {
this.health = health;
}
}
- 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.
Components can be packed into memory, or pooled, depending on your needs.
- Overview
- Concepts
- Getting Started
- Using
- More guides
- Plugins
- Game Gallery
- Tools and Frameworks
- API reference