• 2D
  • YSort with complex Sprite tree and animation

Hi,

I have a Sprite tree consisting of multiples individuals sprites for use in a cut-out animation.

And how it works with YSort on a Map:

What I would like is to be able to freely change the Zindex of the individuals sprites and tell the YSort to sort only the Node2D (see red text on first image) or YSort of the Player but not to sort the individuals sprites, I don't want the Ysort to move the Sprite of which I modified the ZIndex, is that clear ?

Here, I modify the Head index just for demonstration purposes:

And how it look with YSort on a Map:

Can you help me understand how to do that please ? Thanks.

Have you tried to make a Node2d to hold your player, instead of adding the ysort of the player?

Yes, it is the same, the head is drawn behind the tree. If I change zindex of whatever sprites, the YSort interfers and mess up the draw order even thought it should stop ysorting if there is not other YSort node, I don't understant.

Looking at the documentation for YSort, maybe you could have another YSort node in your player and have the sprites in your player children of that node? If I am understanding the documentation correctly, this may make it where all the parts would be sorted as a single object, which I think would fix the issue. You could modify the Z-index of each part of the player to get the proper layering with them still being children of the YSort node, I think.

I have no idea if it would work though, I’m just guessing based on my Godot experience and with what the documentation mentions.

Edit Nevermind, just read the OP and looked at the scene structure and saw that multiple YSort nodes are already being used. :sweat_smile:

I think it's a bug. YSort should only affect direct children. Unless I am missing something, it appears that as soon as you set a z-index anything other than zero (on a child of the child), then YSort doesn't work anymore.

From my search, it seems that YSort does not override custom z-indexing. Maybe this is intentional, but it makes projects like this difficult (because like a character or complex object may have children that you do not want to YSort). I saw some people just rolled their own YSort using z-indexing, that might be an option.

9 days later

I tried everything and I think I will follow your advices and create my own solution.

  • For the TileMap (tree, objects etc.) I will get every tiles and store them in Array
  • Getting all the Children of Nodes in the Scene and store them in a Array
  • Change the Z-index of each Tile (if that possible, I'm sure) in function of their Y Global position
  • Change the Z-index of each Childs in function of their Y Global Position

Thanks.