How is it possible to depth sort tiles and objects in an isometric environments without any limitations? I've been researching this for a while now and there seems to be no publicly available answers to this question.
There are two obvious options for depth-sorting when doing isometric environments:
- Draw all tiles from screen top to screen bottom, followed by all objects from screen top to screen bottom
- Draw each tile and then each object on that tile from screen top to screen bottom
The limitations with number 1 is that tiles cant have different heights because objects will always appear on top of the tiles. Screenshot example:
The limitations with number 2 is that objects can't move between tiles on the x-axis without the tile below overlapping it (because it's drawn later). I've grabbed a screenshot to exemplify this:
I've read lots on bubble sorting and other algorithms, but none of them seem to take this into account, or if they do, they don't document how.
(Please not before answering, this is NOT about how to sort objects that are larger than 1 tile, I'm more than happy with slicing them up so they fit into a tile)
Answer
You can do it with a topological sort (usually) but even with just straight rectangular prisms you can still get cycles, so you have to watch out for that. But you may well be able to avoid that in your level design.
Here's a great introduction (since the article has moved once, this is the code on github, which should hopefully always have a current link to the article):
https://github.com/shaunlebron/IsometricBlocks
http://en.wikipedia.org/wiki/Topological_sorting has two algorithms for doing a topological sort: I've used the depth-first one and just broken cycles by choosing the first one I encountered to be in front. So it won't crash or fail to complete if you have cycles, it will just look wonky. And you can easily report them if you're writing a map editor.
No comments:
Post a Comment