Dynamic depth of sprites based on positions

I need to change depth (z-index) of sprites based on their positions.
In my game I have a flying ‘character’ sprite and hedges which are obstacles.

When my character sprite flies above the hedge sprite and then comes down and overlaps with it, it needs to be behind the hedge. However, if the character sprite is lower than the hedge and then comes up and overlaps it, it needs to be over it, more precisely have a higher z-index/depth than the hedge.

Can someone please tell me is this possible?

See images below for more details.


Yeah update the depth of the sprite when you move it.
When calling moving method also add something like sprite.setDepth(sprite.y)
based on y axis

http://labs.phaser.io/edit.html?src=src/depth%20sorting/isometric%20map.js