1
\$\begingroup\$

I'm currently using LibGDX and Tiled map editor to render isometric maps. I'm having a two related difficulties.

The first issue is, when do I render units that will end up changing position often and to which layer? At first I thought that I would render units with a wall layer so that walls behind of and in front of the unit are drawn correctly. However, the problem with this is that if a unit (i.e. a character) steps in front of say an object in some sort of top-level decoration layer, part of that object will be drawn on top of the unit.

The second issue is how to deal with layers that have static objects that units will often be stepping in front of or behind. Let's say you have a decoration layer where you will place trees. The problem with this layer is that depending on where some objects are placed in the layer, they will overlap inconsistently. For example, the following:

enter image description here enter image description here

I know this is related to painter's algorithm, but I'm using LibGDX's tile map renderer so the extent to which I have control over drawing the map is rendering different layers at a time and switching out cells/tiles in a layer.

\$\endgroup\$
1
  • \$\begingroup\$ I was reading falloutmods.wikia.com/wiki/Fallout_2_editor_introduction and noticed that they have a layer for all scenery. I'm guessing that the scenery is actually not a separate layer that is rendered after/before the wall layer, but everything placed in the scenery layer is drawn in the correct z-order along with the wall layer? I'm not sure if that would solve the problem. \$\endgroup\$ Feb 23, 2014 at 7:03

1 Answer 1

2
\$\begingroup\$

Generally for isometric games, you have to constantly be switching the draw order of images based on their respective tile's y-position (in a game where you have objects all at the same 'z' index, ie not have characters that can jump up to higher levels and such). This means do a sort on the y-position of every tile image (consider storing all the tiles in an array), and then draw these tiles to the screen in that order (lowest y-position to highest y-position).

The only times when you can modify the amount of times you re-order the drawing of the objects, is when you have a constant (can't go below) front layer or a constant (can't go up above) back layer. For anything that can be walked behind or in front of, that object should be drawn as its own tile, and be ordered just like all the other objects.

Another optimization you could do, in cases where, say you have a set of wall tiles that are ordered the same way each render call, but a character which may have moved from behind to in front of an object, is to keep the last frame's ordering for the draw and only insert the non-static tile values into the order.

To be more specific, order the wall tiles once, and keep that array from frame to frame. Then for each frame, clone the ordered wall array, and add in a character at the correct index for its y-position. Then draw that order.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .