How should you do matrix transformations?
You are correct that Transform2D
does not allow these kinds of "additional transforms on top" -- mostly because the transform matrix gets recalculated whenever any underlying property changes. However, you can create a derived class, overriding the transformMatrix
getter so that it applies additional transformations.
I'm not sure what's the best way for implementing isometric games in Flame, but you could try the following approach:
[World]
+--[Ground]
| +--[Tile]s
|
+--[Overground]
+--[Character]
+--[Enemy]s
+--[Structure]s
+--...
Here, Ground
would be a component that applies isometric projection before rendering its children Tile
s (which are just regular PositionComponents). Thus, there's no need to multiply the transform matrix: you are just applying an extra canvas transform.
The Overground
component is a bit trickier. It has many children, each of which is a regular PositionComponent
with (x, y)
position given in the world coordinates. The job of the Overground
then is to apply the isometric projection to that position, converting it into the screen coordinates, and then translate the canvas accordingly before rendering each component. Also, Overground
would need to constantly re-sort the children according to their distance from the camera.