Hello!
First I have to apologise for the wall of text.
I’m trying to make a chart. First I create a group. Then I create a white background and add it to the group.
The group now contains a white background.
Then I create a grid with lines and add that to the group. The Group now contains the background and all the lines. Then I capture the screen with display.captureBounds() to capture only the background and the lines in the background to make one new object that looks like a white background with a grid.
Then I put the new object in a new group. (Previously I deleted all the object in the first group and added the new object)
The problem now is that when I print the new group parents width its the width of the whole screen. Why is that?
I printed the capture bounds xMin and xMax and it was the same as the size of the background. I dont understand why the parent then get the size of the whole screen. The parent of the group should be the object as its the only member of the group.
Here is the code for it.
function init\_chart(width\_s, height\_s) local tabell = {} local grp\_tmp = display.newGroup() local grp = display.newGroup() local chart\_bg = display.newRect(0,0, width\_s, height\_s) --chart\_bg:setStrokeColor(180, 180, 180) grp\_tmp:insert(chart\_bg) grp\_tmp.nrLines = 0 grp\_tmp.line\_hasDot = {} local lines = {} function id\_to\_group(id) for i=1, grp.numChildren, 1 do if(grp[i].name == id) then found = i end end return found end function tabell:add\_grid() local linje = {} local linje1 = {} for i=1, ((chart\_bg.height/50 )), 1 do linje.i = display.newLine( 0, (chart\_bg.height-(i)\*50), chart\_bg.width, (chart\_bg.height-(i)\*50) ) linje.i:setColor(200,200,200) linje.i.width = 2 grp\_tmp:insert(linje.i) print("linje") end for i=1, ((chart\_bg.width/50 )+ 1), 1 do linje1.i = display.newLine( chart\_bg.width - i\*50, 0, chart\_bg.width- i\*50, chart\_bg.height ) linje1.i:setColor(200,200,200) linje1.i.width = 2 grp\_tmp:insert(linje1.i) end -------------------------- -- Capture the bounds of the screen. --display.save(grp, "hehe.png") local copy1 = display.captureBounds(chart\_bg.contentBounds) hej = display.newRect(chart\_bg.contentBounds.xMax, chart\_bg.contentBounds.yMax, 50, 50) print("copy1 w, h " ..copy1.contentWidth .. ", "..copy1.contentHeight) --output 600, 400 As intended print("w, h " ..chart\_bg.contentWidth .. ", "..chart\_bg.contentHeight) --output 600, 400 As intended print("copy1.width "..copy1.width) -- output: 300 ?! should be 600 as the capture (delta) width is 600 -------------------------- grp:insert(copy1) for i=grp\_tmp.numChildren,1,-1 do local child = grp\_tmp[i] child.parent:remove( child ) child = nil end --grp.parent:removeSelf() --grp.parent = nil print("parent width "..grp.parent.width) --output: 768 ?! should be 600 (the parent should be the background object) end return tabell end