zLevel and setContext

Hi everyone,

I’ve been trying to implement zLevel(…) into my game to handle draw order in 2d more efficiently. However, it seems that zLevel doesn’t work when rendering to a texture using setContext. Is there a workaround?


If I recall correctly the zLevel() command uses a depth buffer, and so your setContext() call will need to have a depth buffer enabled as well. Which you can do with a second parameter set to true I think. This was mainly meant for using it with 3D content, but should work the same here.

@John Sorry for my late response. Thanks, this worked!

Unfortunately I forgot that alpha values are ignored when using the z buffer. This means that if I draw one sprite which uses transparency above another sprite, it also draws whatever was drawn at the position where transparent pixel should be. So in my case, it often takes the ground and draws it instead of the transparent pixel. I’ll probably need to stick to my current method unless there is some fix for this. From a quick research, it seems that there are methods in OpenGL that allow to discard alpha values below a certain threshold.

Yeah, zLevel() doesn’t really help with sprites since it doesn’t influence draw order. Modern Codea has style.sortOrder() which does this but obviously that requires using the updated runtime, which is still in development

Great to hear that this will be possible in Codea 4!