EngoEngine / engo

Engo is an open-source 2D game engine written in Go.
https://engoengine.github.io
MIT License
1.75k stars 136 forks source link

TMX resources don't respect transformations when loading tiles #779

Closed jan-xyz closed 3 years ago

jan-xyz commented 3 years ago

Thanks again for this awesome engine! When trying to build a road segment I found that rotated tiles are not rotated in-game.

In Tiled you can rotate tiles (with z) and it also stores it correctly, in the file :

278,2684354838,3221225750,1610613014,

those are 4x the same tile but rotated (0º, 90º, 180º, 270º).

This is how it looks in Tiled:

Screenshot 2021-08-02 at 18 18 35

This is how it looks in-game:

Screenshot 2021-08-02 at 18 19 46

EDIT: This seems to be the location where the Flipping attribute gets lost and should be applied to the image?

https://github.com/EngoEngine/engo/blob/d6f9c6aafb3d9124495edf7115b1b2fb0c35b9c8/common/tmx_level.go#L256-L261

EDIT2: this is the way Tiled calculates the rotation: https://github.com/mapeditor/tiled/blob/ba252f2bb1666510a2cf3851d105db443968f37c/src/libtiled/maprenderer.cpp#L383-L410

My idea would be to calculate the rotation in the conversion from TMX tile to an Engo tile and store the rotation in degree on the Engo tile.

EDIT 3: Another option might be to pass on the individual flags isFlippedDiagonally, isFlippedHorizontally, isFlippedVertically and leave it up to the implementer to work with it.