Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overlapping tiles in TileMaps with Y Sort enabled under a Y Sort node randomly changes rendering order #33230

Closed
AtomaFajrovulpo opened this issue Nov 1, 2019 · 4 comments · Fixed by #42375

Comments

@AtomaFajrovulpo
Copy link

Godot version:

3.1 stable and 3.2 alpha 3

OS/device including version:

All

Issue description:

Having two or more TileMaps under a Y Sort node with overlapping tiles and when both have Y Sort enabled results in them randomly changing their rendering order, in the editor or whilst playing the game.

Steps to reproduce:

Create a V Sort node, add two TileMaps, both with V Sort enabled, create overlapping tiles.

Minimal reproduction project:

TileMap Y Sort Overlap DEMO.zip

@bojidar-bg
Copy link
Contributor

Discussed this with reduz on IRC:

[13:40:01] <bojidar_bg> reduz: sorry for pinging you, I was wondering if https://github.com/godotengine/godot/issues/33230 needs fixing, or is it too much of a performance hit to have a stable sort order on YSorted nodes with equal Y coordinates
[13:40:54] <reduz> bojidar_bg: yeah i guess that should be fixed, maybe comparing X, then Y?
[13:41:20] <reduz> bojidar_bg: i think its a more memory bound operation than CPU, so comparing X and Y should have no cost imo. You can make a small benchmark to test if you want I guess
[13:41:34] <reduz> bojidar_bg: sorry I ment comparing Y, then X if they are the same
[13:52:05] <bojidar_bg> yeah, that would be a good solution
[13:52:34] <bojidar_bg> reduz: maybe add custom sorting axis at the same time? ^^
[13:53:07] <reduz> bojidar_bg: i think that could workm but then that means you would need to convert the sort function to a template
[13:54:09] <reduz> bojidar_bg: but I would do something like this only if we see there is a significant performance hit to adding X

@Pennycook
Copy link
Contributor

I've just encountered this issue in a project I'm working on, and I'm not sure if the stable sort suggested is sufficient for the behavior that I expected. I've modified the original reproducer (by swapping the order of the layers) to show what I'm talking about more easily: TileMap.Y.Sort.Overlap.Layers.DEMO.zip

With Y Sort disabled, all of the red tiles render above the green tiles, reflecting their order in the scene tree:
ysort-disabled

With Y Sort enabled, the order is random, as reported by @AtomaFajrovulpo:
current-behavior

Would it make sense to check the index or Z-index instead of the X coordinate when the Y coordinates are equal? I think that would result in more predictable behavior, and would allow for different tile maps to act more like layers.

@Pennycook
Copy link
Contributor

After playing with this some, I realized that my original suggestion to use Z-index as a tiebreaker doesn't make sense. But tracking the order in which YSort nodes collect their children seems to work: https://github.com/Pennycook/godot/tree/3.2-stable-ysort.

@bojidar-bg: Does this look reasonable to you? Should I open a pull request?

@akien-mga
Copy link
Member

After playing with this some, I realized that my original suggestion to use Z-index as a tiebreaker doesn't make sense. But tracking the order in which YSort nodes collect their children seems to work: https://github.com/Pennycook/godot/tree/3.2-stable-ysort.

As discussed on IRC with @reduz, this seems to be a good solution indeed. Please open a PR against the master branch :)

@akien-mga akien-mga added this to the 4.0 milestone Sep 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants