I am going crazy!!! I have group “P” which I want to zoom to fill the screen. It is sitting in another group. I have tried to set the x,y of the group P to the center of the screen, by using contentToLocal, but it simply does not work.
So I tried a little test, below.
local screenW, screenH = display.contentWidth, display.contentHeight
local g = display.newGroup()
local r = display.newRect(0,0,100,100)
r:setFillColor(100,200,100,150)
g:insert(r)
r:setReferencePoint(display.CenterReferencePoint)
r.x = 0
r.y = 0
g:setReferencePoint(display.CenterReferencePoint)
g.x = 200
g.y = 50
local x,y = g:contentToLocal(screenW/2,screenH/2)
transition.to(g, {x=x, y=y} )
print (x,y)
This code prints the result, “-40, 190”, which is the correct x,y.
However, moving the rectangle, r, instead of the group, actually works fine:
local x,y = r:contentToLocal(screenW/2,screenH/2)
transition.to(r, {x=x, y=y} )
What is going on here?
So, as I wrote this, I figured out that adding the results to g.x will work. That is, -40 + g.x is the center of the screen. Assuming I’m dealing with a group, which my code shouldn’t have to check for. I’m worried there is a bug here. Please tell me what is going on.
[import]uid: 37366 topic_id: 16879 reply_id: 316879[/import]