drawing entities in isometric levels

Started by
3 comments, last by someone2 18 years ago
Hi, I am working on an isometric engine. My engine has a 3D array of tiles. So, an entity can be hidden behind a stack of tiles. I am running into a problem drawing tiles and entities in correct order. I figured the drawing code of entities and tiles will be intermixed, since entities can both cover and be covered by tiles. The problem is, how to draw them correctly. Entities can be in between tiles. All solutions I tried ended up with wrong entity order. It seems the only way to solve it is to use an image mask. I am not sure if this is fast enough Are there any other alternatives anybody has experimented with before? Any help would be greatly appreciated.
Advertisement
The way I do it is that the map keeps track of what entities are over what tile. In the simplest case (if you don't have any complex composite tiles) the drawing is done like:

for all levels in map
-for all tiles in level
--draw tile at position
--draw entities at position

In general the entities positions are floats so that they can be in between tiles and animate smoothly, to keep track of them you naturally need to truncate the positions to the nearest appropriate tile.
Possibly easier way is to use some 3d api for blitting the tiles and utilising hardware zbuffering to keep the drawing order right.
---from www.yellow-hut.com/blog
Hi

I do it by sorting all entities and tiles together and then painting them in the correct order.

I consider everything is 3d with position x,y,z and dimensions dx,dy,dz.

For each one I calculate this value:sortvalue=y+x+((z+dz)*2); where dz is the height of the entity (for tiles/floor entities it could be 0)

Then sort the array using this value. For making it faster, don't resort the entire array each frame, which can also make entities with the same "sort value" to interchange getting some kind of "flickering". Instead, for any entity that moves calculate the next position by moving it down or up in the array. This is faster and does not end up in interchanging of equal valued entities in the array.

This works fine for me.
Option 1:
I think that lots of games don't even try to solve this problem. They just make anything that has height an entity and all tiles flat. They draw the tiles first, and then they draw a z-indexed array of entities (sorted in order of y, and x values).

Option 2:
To have tiles in front or behind entities in a tile map you would have to make the engine completely tile based, where entities are a type of tile, and draw it like this:

for each tile position
-for each layer
--draw the tile/entity

But entities could not be free-roaming, they would be confined to thier tile.

Option 3:
Or you could do what the last post suggests and make everything an entity, and draw them from a z-indexed array.
Thanks. These are nice suggestions. Since I have already passed the designing stage, I must go with option 3.

The suggestion of the anonymous poster looks really nice and innovative. Thanks a lot.

This topic is closed to new replies.

Advertisement