我了解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框架。