I'm new to the Entity Component System pattern and there's something I cannot figure out. Let's say I have the following entity:
Player: {
Components: [
Position: {
x: 0,
y: 0
},
Health: {
max: 100,
current: 50
},
Sprites: { ... }
}
}
When I render an entity that has a Health component I also would like to render a health bar above that entity. Do I treat the health bar as a new entity and attach it to the Player i.e., the Player becomes a composite of entities; or it [the Health bar] should be part of the Health component, in which case how would it be rendered / created?
To illustrate what I'm trying to say:
Player: {
ChildEntities: [
Character: {
Components: [
Position: { x:parent.x, y:parent.y },
Sprites: { parent... }
]
},
HealthBar: {
Components: [
Position: { x:parent.x, y:parent.y },
Health: { max:parent.max, current:parent.current }
]
}
],
Components: [
Position: {
x: 0,
y: 0
},
Health: {
max: 100,
current: 50
}
}
}
Is there an idiomatic / preferred way of doing this? Thanks.