我瞭解ECS模式及其目標解決方案。不過,我正在努力尋找識別組件的最佳方式。同一ECS組件中的多個屬性
例如,我正在製作一款遊戲,您有一艘船並且可以攻擊其他玩家/ NPC並收集資源。
是否需要爲每個屬性分配一個組件?或者我可以在同一個組件中將明顯不相關的屬性分組嗎?屬性?
例如,每個性的成分就應該是這樣的:
// 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;
}
由於每個屬性的多個組件它應該是這樣的:
// 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;
}
我不認爲這會令有所不同,但我使用LibGDX的Ashley框架。