can you trust "width"/"height" for a display group? why don't this code segment work?

In terms of positioning display objects you are placing into a display group, should one be able to trust the “width”/“height” for a display group?   Are there gottchas here which imply you should never rely on these?

Why for example does this code not work.  I’m expecting the red circle to be inside the square in the top right, however this isn’t what I get:

display.setStatusBar( display.HiddenStatusBar ) local outerGroup = display.newGroup() local myRectangle = display.newRect(outerGroup,0, 0, 200,200) myRectangle.strokeWidth = 3 myRectangle:setFillColor(140, 140, 140, 0) myRectangle:setStrokeColor(200,00,0) outerGroup:setReferencePoint(display.TopLeftReferencePoint) outerGroup.x, outerGroup.y = 20,20 local topRightCircle = display.newCircle(outerGroup, 0, 0, 30 ) topRightCircle:setFillColor(128,128,128, 0) topRightCircle.strokeWidth = 5 topRightCircle:setStrokeColor(0,200,0) &nbsp;-- green topRightCircle:setReferencePoint(display.TopRightReferencePoint) topRightCircle.x, topRightCircle.y = outerGroup.width, 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- \<== X setting using outerGroup.width doesn't work

Gives:

Screen_Shot_2013_08_31_at_4_53_42_PM.png

actually - I just noted if I don’t use the inline method to insert the circle into the group it seems to work…so in fact can you trust the width & height parameters, however you have to be really careful in terms of making sure you don’t put objects in using the inline methods and re-aligning them later?  

local topRightCircle = display.newCircle(0, 0, 30 ) topRightCircle:setFillColor(128,128,128, 0) topRightCircle.strokeWidth = 5 topRightCircle:setStrokeColor(0,200,0) &nbsp;-- green topRightCircle:setReferencePoint(display.TopRightReferencePoint) topRightCircle.x, topRightCircle.y = outerGroup.width, 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- \<== X setting using outerGroup.width doesn't work outerGroup:insert(topRightCircle) &nbsp;

actually - I just noted if I don’t use the inline method to insert the circle into the group it seems to work…so in fact can you trust the width & height parameters, however you have to be really careful in terms of making sure you don’t put objects in using the inline methods and re-aligning them later?  

local topRightCircle = display.newCircle(0, 0, 30 ) topRightCircle:setFillColor(128,128,128, 0) topRightCircle.strokeWidth = 5 topRightCircle:setStrokeColor(0,200,0) &nbsp;-- green topRightCircle:setReferencePoint(display.TopRightReferencePoint) topRightCircle.x, topRightCircle.y = outerGroup.width, 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- \<== X setting using outerGroup.width doesn't work outerGroup:insert(topRightCircle) &nbsp;

In your first code, the “width” is 15 pixels wider than the red rectangle because the circle’s left half (15 pixels) is head of the rectangle.
So the circle’s x offset is 15 pixels bigger than you think.
That’s also why your second code works as prefer.
:slight_smile:

In your first code, the “width” is 15 pixels wider than the red rectangle because the circle’s left half (15 pixels) is head of the rectangle.
So the circle’s x offset is 15 pixels bigger than you think.
That’s also why your second code works as prefer.
:slight_smile: