Composer scene self.view not an actual display group?

So I’m reading through all the documentation for Composer right now and got to this part:

The scene object itself is created by calling composer.newScene(). This object holds important data for the scene that Composer must access. For the developer, the most important aspect is the scene’s  view  (self.view) — this is the display group to which all of the scene’s visual content will be added. For example, display objects like images and vector objects must be inserted into the view, along with interactive objects like widgets. This is a critical aspect of Composer.

If the scene’s view is a display group, how come manipulating the X and Y properties of self.view doesn’t actually work? I had to make a child display group, set the X and Y to what I wanted, and then add it to self.view to get the display results I wanted. 

Thats right iz2140, the self.view is like your desktop in your office  and the child-groups and displayobjects you insert into this group is like folders and objects you can shuffle around on your desktop

Hmm, Hendrix, maybe I wasn’t being clear in my first post, but I’d like to know what self.view actually is, rather than just understand how it behaves. If not a display.group then what is it? And why can’t its X and Y properties be manipulated? Thanks.

it’s just a display group.  are you perhaps trying to set x/y while a scene transition is still moving it also?  or are you spelling them (as above) capital “X” and capital “Y”?

Davebollinger, thanks. I tried setting the x and y properties (not capitalized) from within scene.create(). Specifically the code looks like this: 

function scene:create( event ) local sceneGroup = self.view sceneGroup.x, sceneGroup.y = \_W,\_H local toolbar = display.newRect(0, 0, 320, 60) if \_G.isTall then toolbar.y=\_H - 30 else toolbar.y=\_H - 25 end sceneGroup:insert(toolbar) end  

_W and _H are local variables I defined outside of the function:

local \_W = display.contentWidth / 2 --getting the absolute center of the device local \_H = display.contentHeight / 2  

@iz2140,

  1. self.view is simply a display group.

  2. In my opinion, it  is not a good, safe, or reliable practice to modify that group’s position/scale/etc.  Why?  You can’t be 100% sure what is going on behind the scenes.  

For example.  In your code, the assumption is the group has been created, positioned by Corona, and will not have its position changed directly after create() is called.  However, that assumption is most likely wrong.  In all probability, Corona will itself set the x and y values of the group after create() executes.

  1. If you need to manipulate groups (in any way) as part of your storyboard/composer code, I suggest always adding a child group and modifying that group instead:

    local childGroup function scene:create( event ) local sceneGroup = self.view childGroup = display.newGroup() sceneGroup:insert( childGroup ) childGroup.x, childGroup.y = _W,_H … childGroup:insert(toolbar) end … function scene:destroy( event ) childGroup = nil end

roaminggamer nails it - your problem is that you’re attempting it in scene:create

(and also answers the question of whether you should be doing it in the first place – i’ll leave that aside)

the answer is yes, you can, though it’ll only “persist” if composer/storyboard aren’t themselves messing with it also - that’s why i asked if a composer-initiated transition might still be occurring.  composer (and storyboard) set x/y during a scene change (either based on the requested transition or 0,0 if no transition) either way, any position set in scene:create would be wiped out.   a “safe” window where you can mess with it (if you still feel you must) is after show-did and before hide-will.

Thanks for explaining. Roaminggamer’s answer is how I got around the issue as well (by adding a child group to self.view.)

Thats right iz2140, the self.view is like your desktop in your office  and the child-groups and displayobjects you insert into this group is like folders and objects you can shuffle around on your desktop

Hmm, Hendrix, maybe I wasn’t being clear in my first post, but I’d like to know what self.view actually is, rather than just understand how it behaves. If not a display.group then what is it? And why can’t its X and Y properties be manipulated? Thanks.

it’s just a display group.  are you perhaps trying to set x/y while a scene transition is still moving it also?  or are you spelling them (as above) capital “X” and capital “Y”?

Davebollinger, thanks. I tried setting the x and y properties (not capitalized) from within scene.create(). Specifically the code looks like this: 

function scene:create( event ) local sceneGroup = self.view sceneGroup.x, sceneGroup.y = \_W,\_H local toolbar = display.newRect(0, 0, 320, 60) if \_G.isTall then toolbar.y=\_H - 30 else toolbar.y=\_H - 25 end sceneGroup:insert(toolbar) end  

_W and _H are local variables I defined outside of the function:

local \_W = display.contentWidth / 2 --getting the absolute center of the device local \_H = display.contentHeight / 2  

@iz2140,

  1. self.view is simply a display group.

  2. In my opinion, it  is not a good, safe, or reliable practice to modify that group’s position/scale/etc.  Why?  You can’t be 100% sure what is going on behind the scenes.  

For example.  In your code, the assumption is the group has been created, positioned by Corona, and will not have its position changed directly after create() is called.  However, that assumption is most likely wrong.  In all probability, Corona will itself set the x and y values of the group after create() executes.

  1. If you need to manipulate groups (in any way) as part of your storyboard/composer code, I suggest always adding a child group and modifying that group instead:

    local childGroup function scene:create( event ) local sceneGroup = self.view childGroup = display.newGroup() sceneGroup:insert( childGroup ) childGroup.x, childGroup.y = _W,_H … childGroup:insert(toolbar) end … function scene:destroy( event ) childGroup = nil end

roaminggamer nails it - your problem is that you’re attempting it in scene:create

(and also answers the question of whether you should be doing it in the first place – i’ll leave that aside)

the answer is yes, you can, though it’ll only “persist” if composer/storyboard aren’t themselves messing with it also - that’s why i asked if a composer-initiated transition might still be occurring.  composer (and storyboard) set x/y during a scene change (either based on the requested transition or 0,0 if no transition) either way, any position set in scene:create would be wiped out.   a “safe” window where you can mess with it (if you still feel you must) is after show-did and before hide-will.

Thanks for explaining. Roaminggamer’s answer is how I got around the issue as well (by adding a child group to self.view.)