How to make item(s) (ie, GUI) always be drawn on top of other items?

Hi there-

I’m having a little trouble understanding the “stages” and “groups” and how to use them to control what displayObjects are drawn on top, middle, etc.

I’ve realized my GUI is sometimes being covered by in-game items, and would like to fix this. My research points me toward the stages/groups as a fix, however if there is a better way, please let me know. Otherwise…how do I use make those stages/groups work for me, in this case?

Thanks in advance! [import]uid: 69255 topic_id: 12363 reply_id: 312363[/import]

The quick and dirty way

  1. Create a GUI display group
  2. Add your GUI items to the display group
  3. Create an enterFrame event to push your display group to the front of the screen on every draw cycle

Step 3 would look like:

[lua]Runtime:addEventListener( “enterFrame”, function() gui:toFront() end )[/lua]

I don’t normally make games so not sure if the above method takes a performance hit but it pushes the GUI display group to front of the Z order on every frame draw. [import]uid: 11393 topic_id: 12363 reply_id: 47820[/import]

what i do is create several groups

game = display.newGroup()
hud = display.newGroup()
layer1 = display.newGroup()
layer2 = display.newGroup()

then insert all hud images into hud
insert layer1 images into layer1
and layer2 images into layer2

then i insert the groups into game group
game:insert( layer2 )
game:insert( layer2 )
game:insert( hud )

now all your images are organized into different groups one on top of the other [import]uid: 7911 topic_id: 12363 reply_id: 47821[/import]