I’m writing a 2.5D isometric platformer, and from what I’ve read, having many sprites switching between ZOrders would cause performance issues. I’ve thought up a solution, but I’d like to get peoples input to see if there are any ways I could simplify things.
First, I have the normal problem of drawing multiple characters in front of and behind level sprites and eachother:
z0: + + + + +
z1: + + + +
z2: C
z3: C
z4: + + + + +
z5: + + + + +
z6: C
z7: + + + + ++
But on top of that, I have the problem of at least having ten of those layers on top of each other.
z2: z4 z22
z3: z5 z23
... ... ... ...
z9: z11 z29
(I increase by 2 because I have overlapping tiles.)
I thought of using VertexZ instead, because it should be faster as it’s handled by OpenGL, and I should be able to stay way under a thousand different values if I limit the display size, and there are optimizations I can put in later.
But then there’s the problem of the constant swapping of the VertexZ values. For example, whenever a character moved upwards or downwards, it would swap its z-value with the terrain or characters around it:
z1: + + + + + C
z2: C --> + + + + +
z3: + + + + + + + +
I can do that quickly with a linked list representing the vertexz numbers for the current layer,
However, if I were to jump, I would have to insert the character in the order it would end up at on the next layer up. (Now here’s from side view)
z3 z4 z5 z6 z7 z8 z9 z3 z4 z5 C z7 z8 z9
z1 z2 z3 C z5 z6 z7 --> z1 z2 z3 z4 z6 z7 z8
(notice the change in the bottom row)
I could do that quickly with a second, 2D linked list. Since each row of tiles would need to be able to point to the one above it regardless of where any characters were, the linked list would need to only contain terrain.
However, there’s the problem of inserting the character on the next level up and having to reorder the next several rows, and the rows on the lower layers. To fix this, I can insert gaps by only drawing terrain with even z orders at first, but then there’s still the problem of multiple characters on a single row, so I still have to keep the linked list idea.
There still might be a performance issue when many characters are standing side by side on a long horizontal line, but I’m not sure how I would fix that.
So that’s it. That’s my plan for drawing a 2.5D isometric platformer.
It seems like it’ll work, but it also seems like it’ll take a bit of effort to implement and debug. So, before I do that, is there anything that I could do to make that system simpler or better? Or, is there already a library that does what I’m talking about?