ID:2321654
 
Code:
src.layer = MOB_LAYER + (world.maxy - src.y)/world.maxy


Problem description:

The above code works well for pixel movement and layers, allowing you to move in front of a tree and be in front of it visually, and move behind it and be behind it visually. But I'm having a lot of trouble figuring out how to include step_y into the equation, so that if an obj or mob is displaced by so many number of pixels, everything works as it should visually. Could anyone help me? Maths isn't my strong point.
Basically, add step_y (and bound_y) as a fraction of a tile to your whole tile coordinate.
layer = MOB_LAYER + 1 - (y + (step_y + bound_y) / TILE_HEIGHT) / world.maxy

TILE_HEIGHT should be the height of a tile in pixels according to your world.icon_size value.
Thank you, I'll give that a go. Would it be an issue if some of the icons are bigger than the world.icon_size?

Also, what happens when step_y is a negative number, does that tend to mess with things at all?


Edit - The solution you offered seems to work perfectly, thank you. It was driving me nuts. I understand it a lot better now.
I edited my post to include bound_y, which also affects the physical position of your bounding box but isn't changed when you move. I forgot to include it here.

What I usually do is just use a proc that gets the pixel coordinate of the bottom of the bounding box, abstracting away all that noise.