Layer problem in tile-based map

Hi, I am working with a tile-based engine now. My engine consists of 3 layers: a ground layer(grasses, road, etc), an object layer(columns, house, etc), and a topmost layer(cloud, etc). Also, each tile is 32x32 in pixels.

This is my first approach in rendering: ground layer => object layer => all sprites => topmost layer. However, it comes up with some sprites standing “on the top of a tree” rather than standing “behind a tree” in this case.

Then I’ve tried the second approach: divding the object layers to 2 layers, and rendering sequence is now: ground layer => lower object layer => sprites => upper object layer => topmost layer. I was satisfactory with the result until I have decided to use taller sprites (32x96px) instead of the original one(32x64px). Now the head of my sprites is “cut off” by the upper part of trees :’(

So, should I divide the object layers into further more layers? Or you genius here have other better solution?

Get rid of the “layers” scheme and just render in “ground => sprites” order. Make sure you render from the upper-left hand corner of the screen in a left to right, top to bottom fashion. In this way you’ll end up with sprites “closer” to the viewer being on top. (BTW, things like trees need to be sprites in order to show up correctly. If you need them to be tiles, then you’ll need to render ground and sprites simultaneously)

Thx for your helpful advice ;D

So, it’s better to have a Vector or LinkedList to collect all the trees, house, characters, etc, and then apply sorting according to their z-depth before rendering?

No, nothing about Z depth. What I said was that you need to render left to right, top to bottom. Assuming that higher is the -y direction, rendering in this order will force the proper Z order. Of course, I suppose you could use a sorting routine to (potentially) speed up rendering…