find the dimesions of items in group?

hey, i am wondering if there is anyway in Corona in determining the total width (x) or height (y) of the items in a group, for example i have two background images which have the dimensions of 480 x 320

[code]
local game = display.newGroup();
game.x = 0;
game.y = 0;

local sky = display.newImageRect( “sky.png”, 480, 320)
sky:setReferencePoint(display.CenterLeftReferencePoint);
game:insert( sky )
sky.x = 0; sky.y = 160;

local sky2 = display.newImageRect( “sky.png”, 480, 320 )
sky2:setReferencePoint(display.CenterLeftReferencePoint );
game:insert( sky2 )
sky2.x = 120; sky2.y = 160;[/code]

(sky2 overlaps with sky)

so the total width (x) of the group (game) would be 600 right…is there a method that will find this out for me?, or a way to do this? [import]uid: 34863 topic_id: 7199 reply_id: 307199[/import]

to find the total width of a groups children loop the contents of the group and add up the sum of the child objects width property.

function totalWidthOfChildren( group )
local totalWidth = 0
for i=1,#game do
totalWidth = totalWidth + group[i].width
end
return totalWidth
end

print( totalWidthOfChildren( game ) )

That’s one way I suppose [import]uid: 4596 topic_id: 7199 reply_id: 25339[/import]

[lua].contentWidth[/lua]

eg

[lua]-- create square 100x100
local rect1 = display.newRect(0,0,100,100)
rect1:setFillColor(255,0,0,255)

– create another next to it
local rect2 = display.newRect(100,0,100,100)
rect2:setFillColor(255,255,0,255)

– put them in a group
local g = display.newGroup()
g:insert(rect1)
g:insert(rect2)

print(g.contentWidth) – contentWidth is 200[/lua] [import]uid: 6645 topic_id: 7199 reply_id: 25346[/import]

@jmp909 - that method doesnt seem to work when i overlap two backgrounds that are 480 x 320, for example i set background 2 to have an x position of 120; so the total width of the group should be 600, however it still returns a value of 960

@singh206 - this method returns the value of zero everytime :expressionless: [import]uid: 34863 topic_id: 7199 reply_id: 25392[/import]

check your reference points maybe. this gives me 150 width as expected

[lua]local rect1 = display.newRect(0,0,100,100)
rect1:setFillColor(255,0,0,255)
rect1:setReferencePoint(display.TopLeftReferencePoint)

local rect2 = display.newRect(100,0,100,100)
rect2:setFillColor(255,255,0,255)
rect2:setReferencePoint(display.TopLeftReferencePoint)
rect2.x=50

local g = display.newGroup()
g:insert(rect1)
g:insert(rect2)

print(g.contentWidth) – 150[/lua] [import]uid: 6645 topic_id: 7199 reply_id: 25606[/import]