I understand the ECS pattern and what it aims to solve. However I'm struggling to find the best way to identify the components.
For example, I'm working on a game where you have a ship and you can attack other players/npc and collect resources.
Do I need to have a component for each property or can I group apparently unrelated properties in the same component?
E.g, with a component per property it would look like this:
// Components
Position {
int x, y;
}
Velocity {
int speed;
double direction;
}
Sprite {
Image[] images;
}
Health {
int health;
}
Name {
String name;
}
Resource {
// Tag for resources.
}
// Entities
MapEntity {
Position position;
Sprite sprite;
}
ResourceEntity {
Position position;
Sprite sprite;
Resource resource;
}
ShipEntity {
Position position;
Sprite sprite;
Velocity velocity;
Health health;
Name name;
}
With multiple components per property it would look like this:
// Components
MapObject {
int x, y; // Position
Image[] images; // Sprite
}
Resource {
// Tag for resources
}
Velocity { // separated component for static map entities
int speed;
double direction;
}
Ship {
int health
String name;
}
// Entities
MapEntity {
MapObject mapObject;
}
ResourceEntity {
MapObject mapObject;
Resource resource;
}
Ship {
MapObject mapObject;
Velocity velocity;
Ship ship;
}
I don't think it will make a difference, but I'm using LibGDX's Ashley framework.
Aucun commentaire:
Enregistrer un commentaire