The ultimate config.lua and the following “Modernizing” was done to solve a problem, that was simply to make 0, 0 the top, left corner, and display.contentHeight, display.contentWidth the bottom right corner. This gives the app a content area that is guaranteed in letterbox mode to fill the screen exactly but it has a bad drawback in that is the distance between objects cannot be guaranteed. It requires things that should be a fixed distance apart harder to accomplish. Considering these two scenarios:
A Card game with 7 stacks of cards
Angry Birds
In the card game scenario, you are likely going to have the 7 card stacks evenly spread across the screen. If your on an landscape iPad, you only have 480 content area points to draw the 7 stacks. On an HDTV shared phone, you have 570 pixels to show things, so it’s a bit easier to position the cards since the number of points between cards in irrelevant. They can spread out, they can compress together as long as they don’t over lap. The variable config.lua can work for this scenario.
But this would totally stink for Angry Birds because the distance between the slingshot and the pigs would be different on every device and the game would be constantly be playing differently for each different screen shape.
The standard fixed config.lua guarantees that your 0-319, 0-479 will represent the same distance between points regardless of the device. However 0, 0 isn’t necessarily the top, right and display.contentWidth and display.contentHeight is the right, bottom of your content area. Because screens are a different shape, you pretty much have to use display.actualContentHeight and display.actualContentWidth to get the real size of the screen and then add display.screenOriginX, display.screenOriginY to anything that needs to be edge aligned.
Some UI elements can be moved around without impacting the game. Things like the score, a lifebar, a fire button etc. need to be near edges. The distance between the score and the lifebar don’t have to be constant. You want your buttons in the corners for easy reach.
If you look at an iPhone 5 with a 320x480 content area (I’m going to do this example totally as a landscape example, but you still have to consider config.lua in portrait orientation). The actualContentWidth of the iPhone 5 with a fixed 320x480 config.lua will be 568px. The content area is typically centered on the screen. 568 - 480 = 88 content points that are now evenly divided on either side of the content area. This means the left edge is actually at a .x of -44. The right edge is either display.contentWidth + 44 or display.actualContentWidth - 44. They work out to be the same.
There are different strategies at tackling this, but they all involve using display.contentOriginX, display.contentOriginY. In this example .contentOriginX will be -44, .contentOriginY will be 0.
To position the health bar at the top-left corner 50 points from each edge you would do:
healthBar.x = 50 + display.contentOriginX
healthBar.y = 50 + display.contentOriginY
Corona will have calculated the value for contentOrigin* and you know for certain the edge is those pixels away from your content area.
The trick on the other side is that since 0, 0 is already 44 pixels away from the leftEdge, if you want to position your fireButton at the bottom, right, if you use display.actualContentWidth, that part of your app will already be 44 pixels off screen, so you still have to add the contentOrigin* contents to adjust things:
fireButton.x = display.actualContentWidth - 50 + display.screenOriginX – position the button 50 points from the right edge of the screen.
Of course you could take the math.abs(display.contentOriginX) and add that to display.contentWidth to get the same place on the screen.
For your core game elements, keep them within the 0-480, 0-320 range and call it a day. At that point you’re not trying to edge position but content area position.
Let’s switch to an iPad which gives you an effective 360x480 screen. Now display.screenOriginY will hold the value of -20 (360-320=40/2=20) and as long as you are always adding these screenOrigin* constants to edge positioned objects, they will move to the right place on your iPad, and your game elements stay in their 320x480 box.
We recommend that you use a fixed config.lua and write the extra code to add the screenOrigin* constants to your edge positioned items. It’s extra typing but unless you have a game that benefits from variable distance from game objects, you’re better off with the fixed config.lua.
Rob