I am wondering about this behavior with nested display groups.
I am creating a UI library that uses display group nesting, I ran into this behavior.
I am using build 2013. 2100
The following code:
- Has two display groups childContainer and parentcontainer
- childContainer has an rectangle inserted in it initially
- First, I insert an additional object into the childContainer
- The object appears as expected in the container at the offset that was specified
- Last, I move the parentContainer
- This triggers the parentContainer to relayout the childContainer to make it centered
- OK but why is this only being triggered when I move the parentContainer
- Do I get an event to let me know when this is going to happen?
<code>
–bottom most display group
local parentContainer = display.newGroup()
parentContainer.anchorX = .5
parentContainer.anchorY = .5
parentContainer.anchorChildren = true
local parentBackGround = display.newRect(0,0,100,100)
parentContainer:insert(parentBackGround)
–child group
local childContainer = display.newGroup()
childContainer.anchorX = .5
childContainer.anchorY = .5
childContainer.anchorChildren = true
local childBackground = display.newRect(0,0,50,100) – first background
local childBackground2 = display.newRect(0,-50,50,50)-- second background
childBackground:setFillColor(.5,.5,.5,.5)
childBackground2:setFillColor(.1,.5,.5,.5)
childContainer:insert(childBackground) – child group starts with first back ground initially inserted
parentContainer:insert(childContainer) – add the child
parentContainer.x = 500 – move on screen
parentContainer.y= 300
timer.performWithDelay(2000, function () childContainer:insert(childBackground2) end, 1) --insert another object
–notice how at this point the where two objects are located (the first object has not changed position)
timer.performWithDelay(3000, function () parentContainer.x = 550 end, 1)
–notice how moving the parent triggers a relayout of the child within the parent, the child has changed shape and it no longer has the same center
</code>