Trying to get a short function to work (without success) which aligns an underlaying view (group) such that the specific point on the parent view (group) lines up visually (i.e. on top of each other) a point on the underlying group.
Code is below? Know what I’m doing wrong? It moves the child group ok, but not such the points line up…
display.setStatusBar( display.HiddenStatusBar ) system.setTapDelay( 0.3 ) local function createRefPoint(parent, x, y) local myCircle = display.newCircle(parent, x,y, 20 ) myCircle:setFillColor( 1,0,0 ) myCircle.strokeWidth = 0 return myCircle end --------------------------------- -- Preset --------------------------------- -- Cild Group local childGroup = display.newGroup() local childRect = display.newRect(childGroup, 50,50, 300,200) childRect.strokeWidth = 3 childRect:setFillColor ( 1, 0.5 ,1, 0.5 ) childRect:setStrokeColor( 0, 0, 1, 1 ) local childRefPoint = createRefPoint(childGroup, -(childRect.width/2-50), -childRect.height/2+50) -- Parent Group local parentGroup = display.newGroup() local parentRect = display.newRect(parentGroup, 0, 0, 500, 700 ) parentRect.strokeWidth = 3 parentRect:setFillColor ( 1, 0 ,0, 0 ) parentRect:setStrokeColor( 0, 0, 1, 1 ) local parentRefPoint = createRefPoint(parentGroup, -parentRect.width/2,-parentRect.height/2) -- Insert Child Group into Parent Group parentGroup:insert(childGroup) -- Rotate Parent parentGroup.x = display.contentWidth/2 parentGroup.y = display.contentHeight/2 parentGroup:rotate( 20 ) -- -- Rotate Child childGroup:rotate( 45 ) childGroup.x = 20 childGroup.y = 250 --------------------------------- -- Helpers --------------------------------- local function log(txt, o) print(txt, "Local:", o.x, o.y, ", Content:", o.parent:localToContent( o.x, o.y ) ) end local function showPosition(parent, x, y) local myCircle = display.newCircle(parent, x,y, 100 ) myCircle:setFillColor( 1,0,0,0 ) myCircle:setStrokeColor(1,0,0, 1 ) myCircle.strokeWidth = 10 return myCircle end --------------------------------- -- Centre Child Ref Point under Parent Ref Point --------------------------------- -- \*\*\*\* TRYING TO GET THIS FN TO WORK \*\*\*\* local function centreChildRefUnderParentRef(childRef, parentRef) local parentGroup = parentRef.parent local childGroup = childRef.parent local pCx, pCy = parentRef.parent:localToContent( parentRef.x, parentRef.y ) local cCx, cCy = childRef.parent:localToContent( childRef.x, childRef.y ) local dCx, dCy = pCx - cCx, pCy - cCy transition.moveBy( childGroup, { x=dCx, y=dCy, time=700 } ) end centreChildRefUnderParentRef(childRefPoint, parentRefPoint)