I'm trying to develop a simple Zelda-style game. I found this very useful topic

How did LoZ: A Link to the Past handle sub-tile collisions?

that I'm using as reference to develop my collision detection mechanism. However, there's something I've failed to understand. When Link is behind buildings, only part of him is shown. Can anyone please help me understanding how this effect can be achieved? Isn't the building part of the background?

  • \$\begingroup\$ I like to think of the render style as having a ground layer (grass, tile flooring, etc), an object layer (pots, enemies, shurbs, link, etc), and a sky layer (roof tops, lifted pots, tree tops, etc). The logic for moving things between layers can be a bit weird in the example of pots, but that another matter. \$\endgroup\$ Apr 15, 2013 at 22:27

3 Answers 3


2D Tiled games usually have more layers which renders in different layers - some renders in the background others above the player.

That part of the roof renders above the player and that's why player can go behind that building.

Here is the image example from my game to explain better: enter image description here

  • \$\begingroup\$ So the building itself can be a part of the background, but the roof is part of a different layer drawn on top of the layer with the sprites? \$\endgroup\$
    – Tinadm
    Apr 15, 2013 at 21:50
  • 2
    \$\begingroup\$ @Tinadm it doesn't necessarily have to be the entire roof, it could just be the section of roof that would draw on top of the player that's rendered after everything else. \$\endgroup\$
    – Tetrad
    Apr 15, 2013 at 21:53
  • 7
    \$\begingroup\$ +1 for awesome graphics. Really helps the visual learners. \$\endgroup\$ Apr 15, 2013 at 21:56
  • 1
    \$\begingroup\$ I'm pretty sure old SNES JRPGs used the same technique. FF2, FF5, etc. The technique is still valid. \$\endgroup\$ Apr 16, 2013 at 9:44
  • 1
    \$\begingroup\$ You can see this pretty well with emulators, e.g. ZSNES, which allow you to manually switch individual layers off and on. \$\endgroup\$ Apr 16, 2013 at 11:27

While Blodyavenger's answer covers how it is most likely done, here's another possibility which would allow for easy perspective switching (e.g. four or eight different directions, or some camera elevation levels):

Consider the top-down view of your map, e.g.

1 +-----=----+
2 |  .    .  |
3 |    X   o |
4 | .        ||
5 |    .   . |
6 +--=-------+

Where, say, X marks a high pillar. For each object you store images of all possible perspectives (or use the same...), which may be arbitrary many tiles high. Now when drawing, simply start with the column or row that is on the back in the current perspective, e.g. row 1 if looking from south. After that draw the row/column the second-most to the back and so on. This way, when something is higher than one tile (stretched to the current perspective), it will simply overdraw what lies behind.

(Sorry for the lack of nice pictures, I'm not too good at applied graphics...)

  • \$\begingroup\$ Note how you can easily change the camera elevation this way by stretching the object textures \$\endgroup\$ Apr 16, 2013 at 12:04

You should have a variable for depth , and have the images with biggest depth drawn first , then the others with lowest depth. And the depth of each object should equal the negative of its y coordinate.



You must log in to answer this question.

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