I am working on a game engine mostly using ECS (not pure ECS) and I've run into a problem.
Some entities will need a Bounds
component (e.g. a component that has a Rectangle
that represents position, width, and height). Like buttons.
Many entities also need a component that contains the position but not necessarily bounds.
How do I reconcile the overlap?
1) If an entity has both a Bounds
component and a position component, there will be two positions. Not good
2) Entity only has Bounds
component which inherits from position component. Ugly because I have to override the utility methods like translate
from the position component and have it update the bounds object's position. Also then the entity won't have a position component, which is weird.
3) Bounds
component just contains width and height. I don't like this because then I can't use things like a Rectangle
class to represent the bounds.
Any ideas? Thank you.
I would go for 3, with a requirement to have a Transform
component if you have a Bound
component and express the bounds in local frame.
Using a Rectangle
with lower-left and upper-right corners would still make sense since the origin of the bounds are not always the same as the origin of the component.