I want to use some sprite and spriteAnimate in my scene, and they are at the same z axis .
I found they are render order by the x axis position, can i handle it myself?
I want to use some sprite and spriteAnimate in my scene, and they are at the same z axis .
I found they are render order by the x axis position, can i handle it myself?
Hi @Tidus ,
Yes you can, you can use the drawOrder
property on the sprite component:
Just make sure as the tooltip says to assign the sprites on a layer that has the draw order set to manual.
You can also move the sprites on the Z axis
@Tidus There aren’t any sprites in the project?
0 0 , i need create it by code.
Oh, it takes a while to load the sprites. Ok, I take a look
Looks like it’s an issue with the sorting order calculation where it calculates the left most sprite is closer to the camera than the one in the middle so it draws that last
At a different camera angle (face on) it gets the order right for that camera angle:
As the sprites are rendered on the transparent sub layer and the sprite material is set to not write against the depth buffer, the left sprite that is rendered last, renders on top of everything.
While we can fix this specific use case by using a new material for the sprites that enables depth write, you are still going to run into issues with sprites that have opacity as the render order is still incorrect for that camera angle.
If you are just making a 2D game and the camera is going to always look face on onto the sprites, you won’t run into this issue.
If you have sprites mixed in with a 3D world and the camera is going to be moving around at different angles, you may want to consider using a custom material for the sprites and/or even custom sorting logic.
This really depends on your specific use case.