I'm trying to figure out the best way of controlling the display order of my objects. My general approach is to draw objects in the order required, i.e. draw background objects first, then game objects, then overlay objects (pause screen, for example) etc. This works fine.
However, I have hit a problem when using timers to display objects, and the timer finishes after some other code has drawn other objects to the screen. Because of the timing, the objects on screen are drawn in the wrong order.
Should I be grouping objects into display groups, and then forcing those display groups to be drawn in a certain order? This way, timing issues wouldn't occur as long as objects were drawn in the correct display group? Is that correct?
So, for example, I'd have three display groups - background, game, overlay - and I add those to my main display group in that order. Then when I add stuff to one of those groups it will appear in the correct order on screen? So, even if a timer causes Game objects to be drawn after the Overlay objects are drawn, the Game objects would still appear above Background, but beneath Overlay?