Open Poobslag opened 3 years ago
cc @groud
The idea makes sense, but Y-sorting is built into the renderer. Sadly, it's kind of out of the scope of TileMap themselves so I cannot do it myself.
But regarding the proposal itself, I don't think the "Top Left", etc... options are quite difficult to understand. They would make user think that they are sorted according to a diagonal vector, which would not be the case. Instead, Y-sorting should maybe be made an enum with 3 options, something like:
Or we could simply make the X-sorting options another field, I am not sure.
I apologize -- while I promise I searched for similar issues before submitting this one, I just found #664 which is arguably a duplicate. (Or while it describes a different problem, its proposed solution would address my problem as well.)
Regarding the naming, this is a common issue to other libraries and they tend to use concise names. Unity uses names like 'Top Left', 'Top Right', 'Bottom Left' and 'Bottom Right' specifying which tile is drawn first (though I concede it's ambiguous whether the X or Y coordinate is applied first.) GitHub's MapEditor project uses names like 'Left - Up', 'Left - Down', 'Right - Up' and 'Right - Down'. Of course we don't have to copy their names, but I think a typical developer would understand these concise names more intuitively than something more verbose.
I came up with an alternate workaround: by changing the second value in the TileMap's cell_custom_transform
to a very small number like 0.01
, tiles are rendered from left to right. This is because the tiles on the left have an indiscernibly smaller y value. This could be changed to -0.01
to render from right to left.
This does mean that your tiles won't be perfectly horizontally aligned, and will drift by a pixel every 100 tiles. But, this small amount of drift may be preferable to the blinking of the xsort()
function I provided.
Describe the project you are working on
I'm working on a 2D game where a player can wander around an isometric world with a similar perspective to Streets Of Rage or River City Ransom.
Describe the problem or limitation you are having in your project
A tilemap in an isometric 2D game may have many objects with the same Y coordinate, but they cannot be drawn in an arbitrary order. For the isometric perspective in this picture objects must be drawn from left to right to occlude each other naturally, like the top row of objects. If drawn from right to left they look strange, like the bottom row of objects.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Instead of only offering two options, "Y Sort On" and "Y Sort Off", TileMaps could offer more detailed sorting options, giving developers the ability to customize TileMaps to draw things from left to right or right to left.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Currently, TileMaps support provide a Y Sort field. This could be replaced with a Drawing Order field with five options: "Top Left", "Top Right", "Bottom Left", "Bottom Right" and "Off". The "Top Left" sort order would draw objects from top to bottom, and left to right. The "Top Right" sort order would draw objects from top to bottom, and right to left. I can't think of a use case for "Bottom Left" and "Bottom Right" but it makes sense to include them for completeness.
If this enhancement will not be used often, can it be worked around with a few lines of script?
When working with tiles at the same Y coordinate, TileMaps currently break ties by rendering the oldest tiles first. With this limitation, the only way I can think of to work around this limitation is to erase all objects in the TileMap and reinsert them from left to right, something like this.
This code must be executed every time the scene is initialized and every time the TileMap changes. It takes a little while to run and results in a strange visible effect during its duration. It is possible there is a more efficient workaround that I have not thought of.
Is there a reason why this should be core and not an add-on in the asset library?
This is a logical extension of the Godot's current Tilemap functionality, and this is a common feature to TileMaps in other game libraries. As it would replace the current Y Sort functionality it does not seem like feature bloat, but more like replacing a specialized feature with a more generic one.