Composer and Groups within the GROUP

I’m having fun with Composer but confused with making groups within the sceneGroup.  I thought an object could only be in one group at a time.

Many of my objects are in this   scene:create Group below.  

function scene:create( event )

local sceneGroup = self.view

So, I thought I could change the x and y position using

sceneGroup.x = 30

sceneGroup.y = 400

It’s not working though and I figure it’s because it’s not the display.newGroup kind of group.

So, how would I do this?

An object can only be in one group at a time, however groups and be within other groups.  You probably should not change the position of the sceneGroup through.  I have a space shooter where my space ship is made up of multiple objects (5 different shield images, the ship itself, an animated flame coming out the back) and I make a “group” called ship that holds all of the parts.  Then that group gets inserted into the scene’s group for management by the scene.

Rob

Thanks for the reply.  My new group never shows on the screen which is why I didn’t think I could do what you describe.

I created a new group local vowelGroup and  then insert that  sceneGroup:insert(vowelGroup)

Take a look below.   Suddenly those widgets don’t show up on the screen.

[lua]

– Called when the scene’s view does not exist:

function scene:create( event )

        local sceneGroup = self.view

    – Initialize the scene here.

    – Example: add display objects to “sceneGroup”, add touch listeners, etc.

local vowelGroup = display.newGroup( )

sceneGroup:insert( vowelGroup )

–BACKGROUND

    local bg = display.newImageRect(“images/BG_vowels.png”, 1024, 768)

    bg.x = centerX

    bg.y = centerY

    sceneGroup:insert(bg)

–LOGO

    Logo = display.newImageRect( “images/BB_logo.png”, 263, 211 )

    Logo.x = display.contentWidth -915

    Logo.y = display.contentHeight -90

    Logo: scale( .5, .5 )

    sceneGroup:insert(Logo)

–WIDGETS

    local a_btn = widget.newButton

{

    left = 203,

    top = 110,

    defaultFile = “images/a_red_btn_v.png”,

    overFile = “images/a_red_btnPush_v.png”,

    onEvent = play_a_btn

}

    vowelGroup:insert(a_btn)

        local e_btn = widget.newButton

    {

        left = 585,

        top = 110,

        defaultFile = “images/e_red_btn_v.png”,

        overFile = “images/e_red_btnPush_v.png”,

        onEvent = play_e_btn

    }

        vowelGroup:insert(e_btn)

[/lua]

Do you ever insert vowelGroup into sceneGroup?

Line 10 above shows:

sceneGroup:insert( vowelGroup )

That’s what’s strange.  After I do that, the widgets just disappear.

For anyone else having this trouble, the new grouped objects are there but (using my code location above- line 10) they are sitting behind the background image.

So, by just cutting/pasting Line 10  toward the bottom of the code just before “end” of function scene:create, those objects in the new display group come to the foreground.

   sceneGroup:insert( vowelGroup )

end

You have a layering problem.  vowelGroup is inserted before bg, so it’s at the bottom of the stack.  Simply move the sceneGroup:insert(vowelGroup) after you setup the background.

Thanks, Rob.  That’s exactly it.  The new Group just needed to be placed after the Background image.  It need not be placed all the way at the bottom before “end” as I described it above.

So, then to remove the group under scene:destroy,  do I just do this

vowelGroup:removeSelf()

vowelGroup = nil

An object can only be in one group at a time, however groups and be within other groups.  You probably should not change the position of the sceneGroup through.  I have a space shooter where my space ship is made up of multiple objects (5 different shield images, the ship itself, an animated flame coming out the back) and I make a “group” called ship that holds all of the parts.  Then that group gets inserted into the scene’s group for management by the scene.

Rob

Thanks for the reply.  My new group never shows on the screen which is why I didn’t think I could do what you describe.

I created a new group local vowelGroup and  then insert that  sceneGroup:insert(vowelGroup)

Take a look below.   Suddenly those widgets don’t show up on the screen.

[lua]

– Called when the scene’s view does not exist:

function scene:create( event )

        local sceneGroup = self.view

    – Initialize the scene here.

    – Example: add display objects to “sceneGroup”, add touch listeners, etc.

local vowelGroup = display.newGroup( )

sceneGroup:insert( vowelGroup )

–BACKGROUND

    local bg = display.newImageRect(“images/BG_vowels.png”, 1024, 768)

    bg.x = centerX

    bg.y = centerY

    sceneGroup:insert(bg)

–LOGO

    Logo = display.newImageRect( “images/BB_logo.png”, 263, 211 )

    Logo.x = display.contentWidth -915

    Logo.y = display.contentHeight -90

    Logo: scale( .5, .5 )

    sceneGroup:insert(Logo)

–WIDGETS

    local a_btn = widget.newButton

{

    left = 203,

    top = 110,

    defaultFile = “images/a_red_btn_v.png”,

    overFile = “images/a_red_btnPush_v.png”,

    onEvent = play_a_btn

}

    vowelGroup:insert(a_btn)

        local e_btn = widget.newButton

    {

        left = 585,

        top = 110,

        defaultFile = “images/e_red_btn_v.png”,

        overFile = “images/e_red_btnPush_v.png”,

        onEvent = play_e_btn

    }

        vowelGroup:insert(e_btn)

[/lua]

Do you ever insert vowelGroup into sceneGroup?

Line 10 above shows:

sceneGroup:insert( vowelGroup )

That’s what’s strange.  After I do that, the widgets just disappear.

For anyone else having this trouble, the new grouped objects are there but (using my code location above- line 10) they are sitting behind the background image.

So, by just cutting/pasting Line 10  toward the bottom of the code just before “end” of function scene:create, those objects in the new display group come to the foreground.

   sceneGroup:insert( vowelGroup )

end

You have a layering problem.  vowelGroup is inserted before bg, so it’s at the bottom of the stack.  Simply move the sceneGroup:insert(vowelGroup) after you setup the background.

Thanks, Rob.  That’s exactly it.  The new Group just needed to be placed after the Background image.  It need not be placed all the way at the bottom before “end” as I described it above.

So, then to remove the group under scene:destroy,  do I just do this

vowelGroup:removeSelf()

vowelGroup = nil