Any way to create a tree of groups?

Hi,

What I’m trying to do started as a simple assumption on how groups worked and, well, I was apparently wrong.

I have different views of my app as groups. I switch between views/groups by setting their isVisible to false/true or some other kind of transition.

This arrangement works well most of the time. However, there are situations where I need complex widgets which make a lot more sense to be implemented on their own groups and then added to the view group.

In other words, this is somewhat what I try to do:

[lua]local test_group = display.newGroup()
local tmp_bg = display.newRect(test_group,0,0,display.contentWidth,display.contentHeight)
tmp_bg:setFillColor(100,0,0)
local b = Button.new(test_group, {text = “Button”})[/lua]

Button.new returns a group whose parent would be the test_group above. Something like this:

[lua]local button_group = display.newGroup(parent)[/lua]

Several other display objects are added to button_group before it being returned. That way, if I would set test_group.isVisible to false, I would expect that the button_group returned and its children would not be visible (as everything else within test_group).

The problem is that, even though this would be a logical approach, display.newGroup does not seem to process the parent parameter properly. It does not trigger an exception though.

Moreover, the whole coordinate system gets mixed up when I do this and nothing like I wanted really happens. The behaviour goes quite haywire :smiley:

Anyone with ideas on how to deal in these situations? [import]uid: 42811 topic_id: 10067 reply_id: 310067[/import]

Problem solved!

Instead of sending the parent group as a parameter to the sub-group factory function call, you can use the group’s table function like this:

[lua]test_group:insert(button_group)[/lua]

I would recommend changing the interface of display.newGroup() to accept a parent group as all the other factory functions do. It would make a lot of sense. [import]uid: 42811 topic_id: 10067 reply_id: 36842[/import]