Question

What is the proper way to control Z-depth in Corona SDK?

It doesn't seem like sprites inherenty have any Z information being stored.

Was it helpful?

Solution

They have actually...

All sprites belong to a group (even if it is the default group).

The z order is the group index (ie: first sprite in the group get rendered first, and so on).

You cannot change that to a arbitrary value, since sprites cannot share a slot, neither there can be "holes" on the group array.

But there are the functions sprite.toFront() and sprite.toBack()

I personally create more groups to control ordering, one of my apps is a snowglobe, I've create three groups, one for the background, one for the foreground, and between them a layer with the snow, this way I don't have to do background.toBack() and foreground.toFront() every frame.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top