craftworkgames / MonoGame.Extended

Extensions to make MonoGame more awesome
http://www.monogameextended.net/
Other
1.42k stars 324 forks source link

[Tiled] Tiles render in the wrong order. #738

Open Uraxys opened 3 years ago

Uraxys commented 3 years ago

No idea if the title fits the issue, but I didn't come up with anything better.

The problem: If you have a tile set that contains larger tiles than the map tiles (Example, you have a tile set containing tiles that are 32 x 16 pixels, while the map is 16 x 16 pixels), then the larger tiles might be rendered under other tiles.

It's hard to explain, so here is a picture showing the issue: Tiled tiledImage Game gameImage

I'm going to guess this is caused by the TiledMapLayerModel for the trees are being rendered before the rocks, but changing this wouldn't fix the issue (from my understanding), as rocks might be in front of trees and the other way around.

tigurx commented 3 months ago

I have not been able to nail down the exact cause of this bug yet though I am able to reproduce it on the following map: renderOrderBug.zip

It appears this occurs when using a tileset that is larger than the tile size set on the map. In this attached sample map the tile size is 16x16. The objects that are placed on the map are 32x32.

It does appear this bug happens intermittently as we have another map where it renders in the correct render order but we have not been able to figure out why that may be. It is also a 16x16 map with the objects placed on the exact same tiles. The only difference I noticed was the defined tileset order at the top of the tmx file, but even flipping those did not correct the issue on the map where the bug is occurring.

Both the pink square and gray circle are placed on the same layer. Even with all four map Tile render methods I encounter the same issue in game (right-down / right-up / left-down / left-up). I did build the map each time in the content pipeline when switching render orders.

Rendering Correctly in TILED Tiled_ExpectedRender

Rendering Correctly on one of my maps, though I am not sure why InGame_RightRenderOrder

Wrong render order as seen on included map InGame_WrongRenderOrder

I did notice a difference in TILED when I switch the Tile Render Order in Notepad++. I am wondering if possibly this is not being taken into account for some reason even though there are functions for this. When I looked up the purpose of the Render Order, it was for these Z layering issues: https://discourse.mapeditor.org/t/what-is-the-render-order-option-doing/110

Video of difference occurring in TILED when editing render order in Notepad++: https://github.com/craftworkgames/MonoGame.Extended/assets/16768537/74ed273f-6f45-44fd-a15b-6471ba427021