I did a little test where I position a rectangle on the screen using the iPhone 6 simulator and the content in config.lua is set to:
width = 320,
height = 480,
Here the X position = display.contentWidth
prints ( 480 )
Here the X position = display.actualContentWidth
prints ( 569.17333984375 )
As you can see, neither of this values is giving me the desired result I need to position the object at the far right of the screen where only half of its body is showing.
Ironically, the Y value for both “contentHeight” and “actualContentHeight” is giving me the desired result. And they both print the exact same position ( 320 )
The orientation is set to “landscapeRight” and when I change it to “portrait” the problem becomes the height instead of the width.
All Corona objects, by default are centered. That is .x and .y are the center of the object, so if you position a rectangle at display.actualContentWidth, half of it will be off screen.
There are two solutions. You can either adjust your .x to display.actualContentWidth - object.width/2 or you can learn about anchor points. Anchor points allow you to change the default position of .x and/or .y to be any point in the rectangle. You can do something like:
I understand that, and as you can see in the image above, that is not the case. I stated in my post above that I want to position the object at the far right of the screen where only half of its body is showing. Obviously, display.actualContentWidth doesn’t do that.
Because your content area is centered and there is extra space on both sides. Let’s continue to use the iPhone 5 as an example with your landscape app. Your content area is 480 points. The actual screen width is 568. That means there are 88 more points than your content area. With your content area centered, that means 44 points are left of the content area and 44 points tot he right of the content area. Because the content area is already shifted 44 points to the right, you need to add the screenOriginX value (in this example -44) to shift those right edged items back to where you want them.
Or you can use less precise but still accurate code I often include in my many examples:
local w = display.contentWidth local h = display.contentHeight local fullw = display.actualContentWidth local fullh = display.actualContentHeight local centerX = display.contentCenterX local centerY = display.contentCenterY local unusedWidth = fullw - w local unusedHeight = fullh - h local left = centerX - fullw/2 local top = centerY - fullh/2 local right = centerX + fullw/2 local bottom = centerY + fullh/2
PS - Some of these variables are redundant now (over the years Corona has added more display.* fields with useful values), but I still keep mine because I’m used to using them.
PPS - All of my calculations assume you have not modified the screen origins (something I never do).
You can easily make 0 the left most side of the screen by changing the xAlign value to “left” instead of the default “center”. If you do that, then you wouldn’t need to add screenOriginX to your positioning. However, this will break display.contentCenterX, Y because it shifts the content area to the left. You can always make your own centerX, centerY values by doing:
local centerX = display.actualContentWidth / 2
for instance.
Most people center the content area so that play is consistent across all devices. If you play on a taller device like a Galaxy S8 or an iPhone X, you will have your play area shifted even more left, but for your use you might find that works better for you.
And yes, this is an effect of using “letterbox”. You may also find that “zoomEven” might work better for you.
Thanks for your help. I took a look at SSK and it seems to have some useful stuff in it. But I couldn’t find some sort of documentation so I can get a better idea what kind of helpful functions it has and how to use them. Maybe you should do a video showing some of the stuff in there.