Original Post
Hi. I'm currently working on a 2D RPG, more specifically, the graphical part of it. Unfortunately, though, I've hit a roadblock when it comes to drawing the map layers and sprites in the proper order. I was hoping that someone with a bit more experience would be able to point me in the right direction. For reference, I intend for the sprites to move pixel-by-pixel, and they will be able to jump... up to higher places and down to lower places if I can manage that part of it. The first drawing method I tried was to draw each layer of a map, then the sprites on that layer from top to bottom, then repeat the process for each successive layer. However, this caused a problem when a map included things like fences. Here is what I mean. The picture on the left is what the scene should look like, and the animation on the right shows where the problem arises: 
So, to solve this problem, I reworked the process to draw each row of the map one my one, drawing any sprites whose bottom edge falls in that row at the appropriate layer. This seemed to work until I considered the situation of a bridge which sprites could walk across or walk under: 
Next, I tried giving each tile of the map two parts: one to be drawn under sprites on that tile, and the other to be drawn over it. Again, though, a problem came up: 
So now, I'm not sure what to try next. It occured to me that just about all these problems would be solved by treating all the trees, fences, handrails, etc, as objects, and drawing the whole thing at once, at the same time as the other sprites on that layer, but that seems like a bit of a kludge to me, though I could be wrong. I also wonder how I would handle something like a very long staircase, spanning multiple layers, which a sprite could walk up, or behind it. Maybe I'm missing something obvious after thinking about things too hard, or maybe there's already a generally-accepted solution to things like this and I'm just reinventing the wheel here. Anyway, I would greatly appreciate any advice. PS: My artistic skills are bad, but they're not as bad as the pictures above. I just slapped those together quickly to illustrate the problem.

So, to solve this problem, I reworked the process to draw each row of the map one my one, drawing any sprites whose bottom edge falls in that row at the appropriate layer. This seemed to work until I considered the situation of a bridge which sprites could walk across or walk under: 
Next, I tried giving each tile of the map two parts: one to be drawn under sprites on that tile, and the other to be drawn over it. Again, though, a problem came up: 
So now, I'm not sure what to try next. It occured to me that just about all these problems would be solved by treating all the trees, fences, handrails, etc, as objects, and drawing the whole thing at once, at the same time as the other sprites on that layer, but that seems like a bit of a kludge to me, though I could be wrong. I also wonder how I would handle something like a very long staircase, spanning multiple layers, which a sprite could walk up, or behind it. Maybe I'm missing something obvious after thinking about things too hard, or maybe there's already a generally-accepted solution to things like this and I'm just reinventing the wheel here. Anyway, I would greatly appreciate any advice. PS: My artistic skills are bad, but they're not as bad as the pictures above. I just slapped those together quickly to illustrate the problem.