Use of children groups on scenes

Hello!

I’m using scenes with no problem: I add displaying objects on scenegroup. 

But when I have complex user interfaces, I like to group display objects in several groups, so I create groups like this:

function scene:create(event) local sceneGroup = self.view -- keyboard local kbGroup = display.newGroup(sceneGroup) local key = display.newText(kbGroup, "A", ...) -- storyboard local stGroup = display.newGroup(sceneGroup) local points = display.newText(stGroup, "123", ...)

If I do this, then key, points, … don’t disapear from the screen when moving to the next scene.

My question is, Is it a must to use only sceneGroup and not children groups? If not, how must I do it?

Thank you

I don’t think the newGroup() API works like that. You need to explicitly add the groups you created, to the main scene group.

local rect = display.newRect(0, 0, 100, 100) rect:setFillColor( 0.5 ) local nestedGroup = display.newGroup() local group = display.newGroup() nestedGroup:insert(rect) group:insert( nestedGroup )

You want to do this:

function scene:create(event) local sceneGroup = self.view -- keyboard local kbGroup = display.newGroup() local key = display.newText(kbGroup, "A", ...) -- storyboard local stGroup = display.newGroup() local points = display.newText(stGroup, "123", ...) sceneGroup:insert(kbGroup) sceneGroup:insert(stGroup)

Thank you both, with your solution it works.

Anyway, display.newGroup(parentGroup) worked fine for me till now (when no using scenes) :wink:

I don’t think the newGroup() API works like that. You need to explicitly add the groups you created, to the main scene group.

local rect = display.newRect(0, 0, 100, 100) rect:setFillColor( 0.5 ) local nestedGroup = display.newGroup() local group = display.newGroup() nestedGroup:insert(rect) group:insert( nestedGroup )

You want to do this:

function scene:create(event) local sceneGroup = self.view -- keyboard local kbGroup = display.newGroup() local key = display.newText(kbGroup, "A", ...) -- storyboard local stGroup = display.newGroup() local points = display.newText(stGroup, "123", ...) sceneGroup:insert(kbGroup) sceneGroup:insert(stGroup)

Thank you both, with your solution it works.

Anyway, display.newGroup(parentGroup) worked fine for me till now (when no using scenes) :wink: