Simply it's a sequel to my other tutorial; Isometric mouse snapping.
Here is the demo.
Put some ground objects.
In the other tutorial we calculated our grid with two target values. We need to store these values for every ground object. Create 2 instance variable for ground object. Don't forget, for every ground object you need different values. You can calculate this values on debug.
If our player not overlapping ground objects, z-order is unimportant. if it overlaps check for the target value. If it's less or equal then the ground object, put it to bottom, else put it to the top.
But what if you have one thousand ground objects. You don't have to enter the instance variable data by hand. By combining our old formulas you can enter instance variables automatically.
You can find the capx.