(I do not seem to be able to edit/reply to my own postings (?), so a re-post…)
It seems that the contentBounds of the stage object (display.getCurrentStage()) always gives you the display.contentWidth and display.contentHeight coordinates, and the stage’s bounds do not seem to scale with its children’s content-size like other display groups do.
In other words, even if you add display objects that are much bigger than the screen, the stage’s bounds remain the same unlike normal groups.
Is this intended behavior or is it a bug?
(documentation is not clear about this…)
-FrankS.
–
I just wanted to share some more observations about this Stage object (see attached snippet that you can c&p&run in a main.lua).
What it shows is that the Stage’s contentBounds seem to remain on the screen area, no matter what children you add.
That the Stage’s local coordinates can be changed with setReferencePoint to any ReferencePoint on the screen coordinates.
That the Stage’s local coordinates are the global coordinates - as you would expect.
…but that you can also move the Stage object by assigning its local-coordinates, which moves the Stage’s origin, and its contentBounds (still on screen area) and its children.
That latter behavior was for me unexpected as I assumed the Stage could not be moved…
Wonder if all this is the intended behavior… docs are not very clear about it… would love some confirmation/clarification from Ansca…
Thanks, FrankS.
[lua]— Returns the real content-bounds for the current stage group as the contentBounds property only return the screen dimensions and not the real area used by all the Stage’s children.
–@return table with keys (xMin,xMax,yMin,yMax) that indicate the screen area used by the Stage’s children.
function getStageContentBounds()
local CS = display.getCurrentStage()
if(CS.numChildren < 1)then return {xMin=0,yMin=0,xMax=0,yMax=0} end
local bounds = {}
bounds.xMin = CS[1].contentBounds.xMin
bounds.yMin = CS[1].contentBounds.yMin
bounds.xMax = CS[1].contentBounds.xMax
bounds.yMax = CS[1].contentBounds.yMax
for i=2,CS.numChildren do
bounds.xMin = math.min(CS[i].contentBounds.xMin, bounds.xMin)
bounds.yMin = math.min(CS[i].contentBounds.yMin, bounds.yMin)
bounds.xMax = math.max(CS[i].contentBounds.xMax, bounds.xMax)
bounds.yMax = math.max(CS[i].contentBounds.yMax, bounds.yMax)
end
return bounds
end
— Utility function to dump the origin, local, reference, width&height, and contentBounds of a display object.
function xyDump(s,o)
print((s or “”)…": Origin("…o.xOrigin…","…o.yOrigin…"), Local("…o.x…","…o.y…"), Ref("…o.xReference…","…o.yReference…"), wh("…o.width…","…o.height…"), bounds("…o.contentBounds.xMin…","…o.contentBounds.xMax…","…o.contentBounds.yMin…","…o.contentBounds.yMax…")")
end
print(“First an empty stage - contentBounds show screen boundaries”)
CS = display.getCurrentStage()
xyDump(“CS-empty”,CS)
print(“getStageContentBounds:”,“CS-bounds(”…getStageContentBounds().xMin…","…getStageContentBounds().xMax…","…getStageContentBounds().yMin…","…getStageContentBounds().yMax…")")
print(“Add display.newCircle(500, 500, 50 ) outside the screen area”)
local rrr=display.newCircle(500, 500, 50 )
print(“stage bounds remain on the screen area and ignore circle”)
xyDump(“CS-w/circle”, CS)
print(“getStageContentBounds:”,“CS-bounds(”…getStageContentBounds().xMin…","…getStageContentBounds().xMax…","…getStageContentBounds().yMin…","…getStageContentBounds().yMax…")")
print(“set Stage’s reference point at display.BottomRightReferencePoint”)
CS:setReferencePoint(display.BottomRightReferencePoint)
xyDump(“CS-w/refP”, CS)
print(“getStageContentBounds:”,“CS-bounds(”…getStageContentBounds().xMin…","…getStageContentBounds().xMax…","…getStageContentBounds().yMin…","…getStageContentBounds().yMax…")")
print(“localToContent shows that Stage’s local coordinates equal its global ones as we expect”)
print(“localToContent:”,CS:localToContent(CS.x, CS.y))
print(“No we ‘move’ the local Stage’s x,y and we actually see the Stage object move… including its contentBounds (still around the screen area), and all its children”)
CS.x=0
CS.y=0
xyDump(“CS-0”, CS)
print(“getStageContentBounds:”,“CS-bounds(”…getStageContentBounds().xMin…","…getStageContentBounds().xMax…","…getStageContentBounds().yMin…","…getStageContentBounds().yMax…")")[/lua] [import]uid: 8093 topic_id: 8076 reply_id: 308076[/import]