Closed livtanong closed 3 months ago
The anchor
already works like it should for SpriteComponent
it is handled by the PositionComponent
which SpriteComponent
is a subclass of.
Read this section, it might help you understand how the anchor works in Flame components: https://docs.flame-engine.org/latest/flame/components.html#anchor
And otherwise, feel free to join our Discord if you have any further questions about it. :) https://discord.com/invite/pxrBmy4
What could be improved
Make SpriteComponent's render method respect the anchor.
SpriteComponent.render
already makes use ofsprite.render
, which respectsanchor
. All that needs to be done is to pass anchor down to thesprite.render
call.Why should this be improved
It makes intuitive sense. I had to dig into the source to figure out why it wasn't behaving like I expected. I imagine I'm not alone.
Risks
Anchor.topLeft
will break.debugMode = true
will look off because PositionComponent (which SpriteComponent inherits from) does not respectanchor
either, and sorenderDebugMode
will still render a rectangle as if the anchor were at (0, 0).containsLocalPoint
will behave unexpectedly, as it also does not respect the anchor.While (2) and (3) are risks associated with PositionComponent's behavior, I believe PositionComponent itself can stand to also update its behavior to respect
anchor
.More information
For PositionComponent to respect
anchor
, what makes sense to me is to implement abound
orboundingBox
getter, that returns a Rect that takesanchor
into consideration. Thisbound
can then be used by bothcontainsLocalPoint
andrenderDebugMode
in their respective implementations.To mitigate the breaking change, a boolean flag can be set up for users to opt-in to this new behavior, along with a migration warning.
Other