Using y-sort separate from my prop's position?

Godot Version

Godot 4.5

Question

Hello, I’m making a 2D pixel art game that is heavily tile-based with a lot of props which I set by the tile number. I take the tile position, multiply it by the tile size, and I get the top left corner of the tile to place my prop. However, y-sort uses this location as the origin. Is there a way to have it use a different position, perhaps one of the children in prop? Or some other workaround? Otherwise I need to shift the location of all my props when placing them, which feels a bit awkward.

Anyway, thanks in advance.

If you have y-sort active on a parent node, the children will be y-sorted.
This means if your staticbody2d is a child of a y-sort node, it will sort based on the position of the prop, so you have to set the sprite in a way that the 0,0 position of the staticbody is the y-sort-origin.

You can also activate y-sort on the static-body, in this case the sprite would be y-sorted and has to be adjusted to fit your desired origin

1 Like

Okay, so if I’m understanding your first paragraph correctly I’ll need to adjust the position of the prop either way, I can’t just set it to a corner of the tile and have the y-sort origin in the center of the tile. (If I adjust the Sprite it wouldn’t be where I want on the tile).

As for activating the y-sort on the static-body, does that mean the origin would be either in the center (or top left) of the Sprite2d? Which I suppose also wouldn’t achieve what I wanted either, unless I’m misunderstanding something. Well, adjusting all the prop locations isn’t too big a deal anyway, I’ll just make a set_location function that can handle it.

y-sort always looks at the postion of nodes. you technically only have to adjust the sprite and the collisionshape in relation to the parent-node(static-body)

1 Like

Okay, thank you.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.