Using groups in relation to each other?

Hi all,

I’ve been using a singular display group in my current project (a side viewed platformer style game). I’m now at the point where I want to be able to have my background objects contained in one group and my main game/UI elements in another. Is there a way to specify which group “sits” on top of the other? I know I can specify within a group which display object displays on top of others so I’m wondering if there’s some way to do this for groups as well (group01 to front, group02 to back, etc.).

Or maybe there’s another approach?

Also, is it possible to make a group of groups? (groupMain contains group01 and group02 for instance)

Thanks :slight_smile:

Groups can be nested inside other groups which is also how you can control something like a z-index.  Typically i have something like

[lua]

local mainGroup = display.newGroup()

local bgGroup = display.newGroup()

local spriteGroup = display.newGroup()

local hudgroup= display.newGroup()

–the main group is what everything goes into.  The order that i insert the groups determines the z-index.  First items in go to bottom

mainGroup:insert(bgGroup)

mainGroup:insert(spriteGroup)

mainGroup:insert(hudGroup)

[/lua]

In reality my mainGroup would typically be the scene.view from storyboard.  In any case it should give you an idea how to use it in your own implementation.

This is very intuitive now that I see this in action.

I too am using storyboard and I like your idea as far as having the mainGroup be associated with the scene.view

+2 Good Karma to budershank (this is the second time you’ve helped me today!)

Thank you for the help :slight_smile:

PS - I’m assuming I can order/arrange the groups in mainGroup just as I would display objects in the other groups :slight_smile:

Yup, should be able to though I’ve never had to much more than I posted above.

Groups can be nested inside other groups which is also how you can control something like a z-index.  Typically i have something like

[lua]

local mainGroup = display.newGroup()

local bgGroup = display.newGroup()

local spriteGroup = display.newGroup()

local hudgroup= display.newGroup()

–the main group is what everything goes into.  The order that i insert the groups determines the z-index.  First items in go to bottom

mainGroup:insert(bgGroup)

mainGroup:insert(spriteGroup)

mainGroup:insert(hudGroup)

[/lua]

In reality my mainGroup would typically be the scene.view from storyboard.  In any case it should give you an idea how to use it in your own implementation.

This is very intuitive now that I see this in action.

I too am using storyboard and I like your idea as far as having the mainGroup be associated with the scene.view

+2 Good Karma to budershank (this is the second time you’ve helped me today!)

Thank you for the help :slight_smile:

PS - I’m assuming I can order/arrange the groups in mainGroup just as I would display objects in the other groups :slight_smile:

Yup, should be able to though I’ve never had to much more than I posted above.