TheBoneJarmer / TiledCS

TiledCS is a dotnet library for loading Tiled tilesets and maps
MIT License
139 stars 51 forks source link

High level tile rotation access #97

Open ironcutter24 opened 1 year ago

ironcutter24 commented 1 year ago

Trying to give high level access to tile rotation and other transform related information by implementing a GetTileTransform() method that returns a TileTransform object.

Said object contains:

int Rotation => tile rotation in degrees inferred by flip flags
Flip flip => original flip flags minus the ones translated into a rotation
Flip flipRaw => original flip flags
Point offset => tile offset to keep position unchanged after a rotation around its upper-left corner

I had a request to implement this in my MonoGame example repository, but seems reasonable to have it built into TiledCS. This simplifies implementation for MonoGame by a lot, and I hope for other platforms too.

It is a known issue that when all flip flags are true (and you get both rotaton and flip in the TileTransform) the result of the transformation depends on the order these transformation are applied. It is implemented so that the rotation has to be applied first, and works fine with MonoGame, but may require some more attention.