Display order of display objects

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?

if you create group1 first then group2 all objects added to group1 will be under objects in group2 even if its added at a later. you may also specify the position where you want to add objects to a group using group:insert(pos,object) where pos is the position where you want to add the object to.

Thanks for the info :-)

views:1541 update:2011/10/11 15:24:38
corona forums © 2003-2011