Tile map doesn't layer correctly with other nodes

Godot Version



First of all, thank you for checking out my problem.
I’m trying to use a Tile Map for a 2D game but the layering doesn’t work properly with nodes that aren’t part of the Tile Map.
I want to have a layer of the Tile Map that will be be displayed behind or in from of the player depending on where the player stands.
From what it seems to me when the node reaches the middle of the tile it goes behind it but not the entire layer either as it will still be above the next tile above it.
I am using Y Sort for all of this.

If anyone has any suggestions or fixes please let me know.
Thanks in advance.

if you are not using layers, i recommend you look into tile map layers. here is a tilemap i created in the editor. the blue tile (behind the white square) is on Layer 0. the magenta tile (in front of the white square) is on Layer 1. for Layer 1, i set z-index to 1.

attached is a screenshot of white square between layer 0 and layer 1. also attached is the tile map in the editor.

(if you have not read the documentation, please do so)


My problem is with things like the player or other nodes outside of the Tile Map. The Tile Map layers work fine for me so far but I need to allow for dynamic parts in the game to be able to be displayed in font or behind certain layers of the tile map depending on the situation.
For instance, if I want the player(not part of the Tile Map) to go behind a tree(part of the Tile Map) I need the tree to be displayed above the player when the player goes passed it but not when the player hasn’t.

you can use set_layer_z_index and other functions to change layer properties based on conditions in your game. the same functionality is available for canvas item nodes, such as sprites.

Interesting. I’ll give it a try.
Thank you

If I understand, doesn’t using this method means every layer will need to only contain a single object since changing the z_index of a layer will change everything within that layer?
There has to be a better solution

I don’t thinn you need to change it for every object, just for the ones that do not eitk properly after starting to use the layers.
Hope this works