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.