object width change after I capture it with display.captureBounds()

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                     

I’v added something.

This is from the new version of the init_chart() function:

local chart\_bg = display.newRect(0,0, width\_s, height\_s)                 chart\_bg:setFillColor(0,0,40)         chart\_bg:setStrokeColor(96, 96, 96)          chart\_bg.strokeWidth = 1;            chart\_bg:setReferencePoint(TopLeftReferencePoint)           print("Chart bg Y y"..chart\_bg.y)   --Ouputs: 150 !!!!!         print("Chart bg Y yOri"..chart\_bg.yOrigin) --Outputs: 150 !!!         print("Chart bg Y yRef"..chart\_bg.yReference) --Outputs:0               grp\_tmp:insert(chart\_bg)  

Chart_bg’s y coordinate shouldnt chage to 150 unless I say so! Right?

It is the same with our without seting reference point.

Can someone please explain this to me?

I’ve used groups and childrens/objects in groups before and I’ve used there x and y coordinates without trouble.

PS, I hope the code insn’t as messy as it is on my ie Explorer. It looks right when I add it in the reply field and surround it with code taggs.

DS

I am using display.save() in my app, but I believe all the display screen cap functions operate the same when grabbing content. The note in the display.save() documentation reads:

" NOTE: When dynamic content scaling is enabled, display.save()saves the image in the device’s native resolution. For instance, if this method is used to save a 100 x 200 pixel display object, it will be saved as a 100 x 200 image on iPhone3 but it will be a 200 x 400 imageon an iPhone4 (which would have the same content dimensions but more actual pixels). This is assuming that the config.lua file specifies the content width/height as 320x480 respectively."

So if your app is set in config.lua to a virtual 320x480 screen, the actual captured inmage will be MUCH larger. In my app , I am scaling the groups before I capture them using display.contentScaleX,Y as a factor so that I grab the right amount of pixels.

Don’t know if this is the source of your error, but jut thought I’d throw that out there.

Regarding the yOrigin value in your last post, I believe that represents the number of pixels OUTSIDE of you app area… If you have a 320x480 (2:3) layout defined in your config.lua, but the device is shaped differently, the SDK may set your app up inside a frame on the device (the black borders)… The xOrigin, yOrigin variables represent the number of pixels in from the side/top of the device screen that the SDK must use to frame your app / do the content scaling properly. (display.xOrigin does that anyways… not sure how that translates to objects in a group).

I’v added something.

This is from the new version of the init_chart() function:

local chart\_bg = display.newRect(0,0, width\_s, height\_s)                 chart\_bg:setFillColor(0,0,40)         chart\_bg:setStrokeColor(96, 96, 96)          chart\_bg.strokeWidth = 1;            chart\_bg:setReferencePoint(TopLeftReferencePoint)           print("Chart bg Y y"..chart\_bg.y)   --Ouputs: 150 !!!!!         print("Chart bg Y yOri"..chart\_bg.yOrigin) --Outputs: 150 !!!         print("Chart bg Y yRef"..chart\_bg.yReference) --Outputs:0               grp\_tmp:insert(chart\_bg)  

Chart_bg’s y coordinate shouldnt chage to 150 unless I say so! Right?

It is the same with our without seting reference point.

Can someone please explain this to me?

I’ve used groups and childrens/objects in groups before and I’ve used there x and y coordinates without trouble.

PS, I hope the code insn’t as messy as it is on my ie Explorer. It looks right when I add it in the reply field and surround it with code taggs.

DS

I am using display.save() in my app, but I believe all the display screen cap functions operate the same when grabbing content. The note in the display.save() documentation reads:

" NOTE: When dynamic content scaling is enabled, display.save()saves the image in the device’s native resolution. For instance, if this method is used to save a 100 x 200 pixel display object, it will be saved as a 100 x 200 image on iPhone3 but it will be a 200 x 400 imageon an iPhone4 (which would have the same content dimensions but more actual pixels). This is assuming that the config.lua file specifies the content width/height as 320x480 respectively."

So if your app is set in config.lua to a virtual 320x480 screen, the actual captured inmage will be MUCH larger. In my app , I am scaling the groups before I capture them using display.contentScaleX,Y as a factor so that I grab the right amount of pixels.

Don’t know if this is the source of your error, but jut thought I’d throw that out there.

Regarding the yOrigin value in your last post, I believe that represents the number of pixels OUTSIDE of you app area… If you have a 320x480 (2:3) layout defined in your config.lua, but the device is shaped differently, the SDK may set your app up inside a frame on the device (the black borders)… The xOrigin, yOrigin variables represent the number of pixels in from the side/top of the device screen that the SDK must use to frame your app / do the content scaling properly. (display.xOrigin does that anyways… not sure how that translates to objects in a group).

The problem is that the captured picture looks right, with the right size, but the x- and y-coordintes for the new Picture is “outside” the picture.  

Edit:

If I print out the group’s x and y where the Picture belongs to I get correct x and y. But if I print out the Pictures x and y its way off. Shouldn’t the x and y of the Group and Picture be the same if the Picture is the only member.

PS This time I didn’t care to change the uppercase letter that my Words gets autoINcorrected to!

DS

The problem is that the captured picture looks right, with the right size, but the x- and y-coordintes for the new Picture is “outside” the picture.  

Edit:

If I print out the group’s x and y where the Picture belongs to I get correct x and y. But if I print out the Pictures x and y its way off. Shouldn’t the x and y of the Group and Picture be the same if the Picture is the only member.

PS This time I didn’t care to change the uppercase letter that my Words gets autoINcorrected to!

DS