I am working on a scrolling 2D game (I think Red Alert or Zelda), but I am bullied with a drawing.
Basically, there are two types of objects that are drawn on the map. Some of them have fixed positions (for example, trees and buildings), while others move (players, enemies, flying arrows).
In order for things to be displayed opposite each other correctly, they need to be drawn in a certain order (first, removed objects and work in the direction of the "camera").
Now I sort the list of all objects (both types) every time the game is updated (100 times per second), and this seems like a huge waste of processor time. The order of objects rarely changes, and when they do, they usually only move one item up or down in the list.
Another problem is that you need to consider only those objects that are actually on the screen. Since maps can become quite large with 1000 objects, I donβt want to sort them all 100 times per second.
How do you suggest me to solve this?
source share