What is the best way to render the meta sprites in my game in a different order in every frame?
In the moment, all my characters data is stored in an array:
Index 0: Player character
Index 1: Opponent 1
Index 2: Opponent 2
Index 3: Projectile
Index 4: Flying object
Then I iterate through this array and call the RenderSprites function for each of these characters which takes the X and Y coordinate as well as the index to an array where all possible meta sprites are stored and then puts the necessary sprites on screen.
This way, the player character is always drawn on top.
Which, in general, is not bad, but unfortunately, some of my characters can move outside the platforms and are therefore sometimes in front of the house wall. And it looks strange if the player stands on the roof while the feet of the opponent are in front of the house wall, but the opponent's head is behind the player character.
So, what can I do to change the order every frame without having to waste too much CPU time for it?
By the way, I always want to change the order of whole meta sprites, not single hardware sprites. So, when you pause the emulator while two characters are overlapping, then one whole character shall stand in front of the other one. I don't want a scene where in the same frame, 50 % of a specific character stands in front of another character while 50 % of it stands behind the other one. (Unless this would require too much work and the other method is much faster.)
In the moment, all my characters data is stored in an array:
Index 0: Player character
Index 1: Opponent 1
Index 2: Opponent 2
Index 3: Projectile
Index 4: Flying object
Then I iterate through this array and call the RenderSprites function for each of these characters which takes the X and Y coordinate as well as the index to an array where all possible meta sprites are stored and then puts the necessary sprites on screen.
This way, the player character is always drawn on top.
Which, in general, is not bad, but unfortunately, some of my characters can move outside the platforms and are therefore sometimes in front of the house wall. And it looks strange if the player stands on the roof while the feet of the opponent are in front of the house wall, but the opponent's head is behind the player character.
So, what can I do to change the order every frame without having to waste too much CPU time for it?
By the way, I always want to change the order of whole meta sprites, not single hardware sprites. So, when you pause the emulator while two characters are overlapping, then one whole character shall stand in front of the other one. I don't want a scene where in the same frame, 50 % of a specific character stands in front of another character while 50 % of it stands behind the other one. (Unless this would require too much work and the other method is much faster.)