Screen Positioning across devices

Hi guys,

Even though similar questions have been asked before, I still can’t get positioning of my objects properly on my screen across different devices and would appreciate some help.

I have two display groups full of objects and I want them centered vertically, without overlapping each other. This is the code I use:

local minVisibleX = display.screenOriginX local maxVisibleX = display.viewableContentWidth - display.screenOriginX local minVisibleY = display.screenOriginY local maxVisibleY = display.viewableContentHeight  - display.screenOriginY local xMid = minVisibleX + (maxVisibleX - minVisibleX)\*0.5 local yMid = minVisibleY + (maxVisibleY - minVisibleY)\*0.5 .... mydemo.demoGroup:setReferencePoint(display.CenterReferencePoint) mhelper.menuGroup:setReferencePoint(display.CenterReferencePoint) mydemo.demoGroup.y = yMid - 0.5\*mydemo.demoGroup.height mhelper.menuGroup.y = yMid + 0.5\*mhelper.menuGroup.height  

 

And I always get the top and bottom of the groups cut off, with a big chunk of empty space between them, instead of the demogroup’s bottom being up against the menugroup’s top.

thanks in advance to anyone helping me stop pulling out any more hair!

Z

You could jettison half the math and use  display.BottomCenterReferencePoint for demoGroup and display.TopCenterReferencePoint for menuGroup… If that works as expected, it could solve your problems. If it doesn’t work as expected, the simpler case might shed more light on the source of the error.

Thanks for your reply. All those vars are used elsewhere to position objects in my code; I just copied and pasted them all into the post.

But I did manage to resolve the issue by setting the reference points as you suggest and they align properly now. I don’t know why what I had didn’t work (as it works for other display groups I line up), but I’ll move on from it for now as it was taking too much time!

You could jettison half the math and use  display.BottomCenterReferencePoint for demoGroup and display.TopCenterReferencePoint for menuGroup… If that works as expected, it could solve your problems. If it doesn’t work as expected, the simpler case might shed more light on the source of the error.

Thanks for your reply. All those vars are used elsewhere to position objects in my code; I just copied and pasted them all into the post.

But I did manage to resolve the issue by setting the reference points as you suggest and they align properly now. I don’t know why what I had didn’t work (as it works for other display groups I line up), but I’ll move on from it for now as it was taking too much time!