0

I'm writing a 2D game with an internal 3D space. The view is 3/4 view. I've run into trouble with the render order of entites.

Context: The world uses a tile system, like a 3 dimensional lattice, each tile is a 1x1x1 space. Entities have a 3D coordinate position and do not snap to tiles(may straddle two tiles). Entities have their own width, height, and depth, all entities are strictly oblongs and do not rotate(only exist in right angles). Since the view angle is fixed and there is no perspective, the graphical representation of the tiles and entities are all 2D images(they are all sprites)

Question: How do I code for render orders in a 3/4 view?

So far, I've defined the render order using the y and z coordinate of the entity(I believe x coordinate is irrelevant in 3/4 view). However, it quickly dawned how using a single point to define the layer of an entity with a height and depth was bound to have issues. This is illustrated in the following image: enter image description here The horizontal axis is y, while the vertical axis is z. The dashed line represents the view angle.

The blue box and green box should be rendered above the red box. However, when the render order is determined by either the y or the z coordinate of the entity's origin point(highlighted), it is impossible for the system to be consistant.

For instance, if the renderer renders from lowest to highest(layer based on z coordinate), the red box would cover the green box, which is incorrect. If the render renders from back to front(layer based on y coordinate), the red box would appear on top of the blue box, which is incorrect. A mixture of y and z coordinate(e.g. y + z = layer) would be inconsistant also, though it does agree with the example shown.

Without assumptions about the features of the game I am creating, is there a way to have a system that can consistantly order render layers correctly, given information of 3D coordinate position and dimensions of all entities? Also given that each entity is represented as a flat, 2D sprite?

I have encountered numerous sites warning people away from 3D, since it is "orders of magnitude" harder than 2D. Could I walk the tightrope and introduce some 3D elements to solve this issue, while keeping the game 2D and in 3/4 view angle? Thanks in advance.

  • 1
    I don't agree that 3D is necessarily harder, and sorting is one of the areas where it may actually be easier, since we've had to implement robust solutions to it to make 3D work at all. That said, we have lots of past Q&A about solving sorting problems in 2D, usually recommending a topological sort. How have you tried putting these existing answers into practice? Where do you run into an issue that the existing answers don't help you solve? – DMGregory Dec 19 '20 at 11:51
  • 1
    Thanks for the link you posted, I found a couple of others who asked pretty much the same question with varying levels of success. I think what I gathered is that I need to manually compare the order of entities that have their 2D representations overlapping, allowing me to take into account their height and depth. Gonna test some stuff out and will be sure to post answer here when I figure it out. – Chuan Li Dec 19 '20 at 22:37
  • Also thanks for disambiguating the 3D thing. Had a feeling using some elements of 3D would simplify the problem but I'm still a beginner so just needed someone to tell me straight up :) – Chuan Li Dec 19 '20 at 22:39
  • So in the end I couldn't find a simple solution and decided to go 3D. I suppose a manual sort(comparing the sort order of all overlapping objects) would have worked, but in my case all terrain tiles counted as objects and a full sort would inevitably involve all objects in the scene, which deterred me from using this method. – Chuan Li Dec 26 '20 at 05:02

0 Answers0