-1
\$\begingroup\$

I've been working on a custom tile-based map editor for a while now, and everything works as expected, or so I thought until I've tried rendering the actual map including the dynamic objects as well.

As it currently works, it's saving data into a buffer in a format of: [ground layer] [on-ground layer] (flowers/rocks) [wall layer] [on-wall layer] (windows/torches/bookshelves)

So basically there's a total of 4 layers. The tiles are rendered from top left corner to bottom right corner in the following order: [ground layer] -> All tiles [on-ground layer] -> All tiles [wall layer] Does an instance exists on that spot? in case it does the instance gets rendered first, and then the tile itself. [on-wall layer] renders normally right after that.

This system seems perfectly fine it the game has a grid-based movement, as well as if all the dynamic sprites are the same size like the tile size. Why? Well, you'd just walk anywhere and get covered with a certain tile or be drawn over a certain tile. On the other hand, if any of the dynamic instances has let's say a sprite height which is bigger than the actual tile size the depth sorting issues appear.

Example: We've got a pillar which is 16x48 in size. The very bottom of the pillar has a collider of 16x16 and it can't be stepped on, but the mid and top part don't have any colliders. Now if a player for example steps on the topmost tile of the pillar everything gets rendered normally. On the other hand if the steps on the mid tile, the "player's head" would be rendered over the topmost tile..

Screenshot of tile map sorting problem

I'm wondering if there's an actual solution for depth ordering in a case like this.

\$\endgroup\$
  • \$\begingroup\$ As you can probably imagine, you're not the first developer to wrestle with sprite sorting in isometric games. Have you searched through our catalog of existing Q&A on the topic? You may find answers you can start using right away, rather than waiting for a new one to be written. If you find something that looks like the right solution to you, but you have trouble understanding or implementing it, you can edit your question to focus on that last hurdle to get answers targeted at that specific issue. \$\endgroup\$ – DMGregory Sep 15 '18 at 12:21
  • \$\begingroup\$ It's not isometric sorting, it's basic 2D flat sorting but the problem is that it's tile based and all tiles have the same size. \$\endgroup\$ – TheDBeetle Sep 15 '18 at 13:53
  • 1
    \$\begingroup\$ Whoops, I missed that. I've embedded your image in the question so it's more obvious. Fortunately, you're also not the first developer to make a non-isometric tile-based game with objects that span multiple tiles. See this tackled here and here and here for example. Try searching around these and other Q&As on the topic to see if there's an answer you can use already. \$\endgroup\$ – DMGregory Sep 15 '18 at 14:13
  • \$\begingroup\$ Well, none of these match the problem at hand sadly. They are all somewhat connected but they don't fit into the bigger picture. \$\endgroup\$ – TheDBeetle Sep 15 '18 at 15:19
  • \$\begingroup\$ Editing your question to clarify how your situation differs from what's covered in the resources you've found so far, and where you're stuck trying to apply those answers to your case, can help users target their help more effectively. \$\endgroup\$ – DMGregory Sep 15 '18 at 15:23
0
\$\begingroup\$

For this scenario, simply have your oversized sprite take up multiple tiles (e.g. create a virtual tile for the oversized sprite one above the actual tile). This way, when you go about checking for what to draw, you'll see there's a wall and a ground object to draw. At this point, to figure out which overlaps which, check the ending vertical tile of each. Assuming vertical indices increment from top to bottom (top tile row is index 0, bottom tile row is index X), the one with the higher ending vertical tile is in front of the other. On a tie, you'll have to figure out which one you want to use, but in theory it shouldn't happen with proper collision.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.