28

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?

Tinadm
  • 443
  • 4
  • 6
  • 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. – Benjamin Danger Johnson Apr 15 '13 at 22:27

3 Answers3

32

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

Blodyavenger
  • 541
  • 5
  • 9
5

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.

  ABCDEFGHIJKL
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...)

Tobias Kienzler
  • 996
  • 12
  • 25
1

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.

Depth=-y