I’m still figuring out sorting myself, but I think that adding the torch nodes as children of the
walls tilemap (assuming the root node of the torch is in the same position as the torch sprite), then the
walls tilemap should sort the wall tiles, the character, and all the torch nodes based on their Y position. Although, I can see a small issue where the Y position of the wall tile matches the wall tile, causing the wall to be on top (maybe). This should be fixable by moving the torch down a little (by 1px or even less).
Now the node setup is this:
and…the issue remains
I’ve tried some more variations of the nodes placement in the tree and none of them worked as I wanted. In some setups, the Y sorting didn’t work, but the character was drawn in front of the torches. In the other setups, everything was the other way round. Looks like it’s either impossible(hope it’s not) or rather tricky to achieve.
Ceilingdoor | 2016-05-07 09:21
I think you misunderstood me. I’m assuming “torches” is basically a folder node. Inside you have instances of torch scenes (for example, something like a Node2D with a Sprite and a Particle2D as children, similar to that character instance). See how you don’t have a “characters” node and instead just made the character instance a child of “walls”? So what I’m saying is that you should get rid of the folder node “torches” and add each “torch” instance as a child of “walls”, exactly as you did with the “character” instance. Because the way Y-Sort works (in the TileMap node and in the Y-Sort node), is that it orders its direct (ex: the character’s root node is the direct child of the “walls” TileMap node) children based on their Y position.
Edit: just to clarify, right now the Y-Sort is sorting the “torches” folder node, instead of the torch instances inside of it
batmanasb | 2016-05-07 09:35
Oh, yes, I did misunderstood you. I’ve got rid of the folder node:
The Y sorting kinda works, but not the whole character sprite is affected:
Ceilingdoor | 2016-05-07 10:15
Now I think you just need to mess around with the position of the root nodes. Figure out which part of each root node is the origin aka position (0,0), and move the parts around while keeping the origin at position (0,0). This is the part I’m even less experienced with, but I think some nodes have the origin on the top left corner of the node (probably KinematicBody2D), and others such as Sprites might have the origin at the center. Also, I think tiles are center, but I’m not sure.
So you basically just need to move the contents around until it looks right. I think the easy way might be to simply change the Y offset of the torch sprite (to about -10) and then shift the children nodes that amount as well. But I never tried this myself, so I can’t know if that will work. But the other option is to add a Node2D as the parent of the torch Sprite, and simply change the position of the Sprite, and this way the children will move as well (unlike with offset).
But yeah, then you’re basically done!
batmanasb | 2016-05-07 10:42
I messed around with the origins and offsets and it’s working as it should now. Thanks for seeing me through!
Ceilingdoor | 2016-05-07 11:43