Screens have different widths. With that config.lua most of your screens will be 320 points wide, though iPads will be 360 points wide. Because of this anything you position with just a obj.x = somevalue will be that far from the left edge but the background is being centered. That means the extra 40 points of screen real estate is divided by 2, giving you 20 extra points on the left to work with and 20 extra points on the right to work with.
There are two ways to deal with this. Since you’re using a config.lua from the tutorial “The Ultimate config.lua”, it’s assuming that you desire to have 0, 0 always be the top left and display.contentWidth, display.contentHeight to always be the bottom right of the screen. When you do this, you need to position things in a relative fashion. That is you ask yourself:
How many points from the left edge do I want something?
How many points from the right edge do I want something?
How far from the bottom edge? The top edge? and most importantly:
How far from the center do I want something?
In your images above, the blocks are pretty much centered and somethings like the green object get cut off on the narrower screen. Because 0, 0 changes based on the device, for thing you want to stay in the center (or some distance from the center) you would do:
obj.x = display.contentCenterX or
obj.x = display.contentCenterX + 25
You only use fixed numbers like:
obj.x = 10 if you want the object to always stay 10 points from the left edge, or:
obj.x = display.contentWidth - 10 to keep it 10 points from the right edge. Objects positioned like this will move relative to your background but for things like scores, home buttons, help buttons that you want to tuck at the top or bottom or at the sides, and their position on the background doesn’t matter this works well.
When you need to always use: obj.x = some value and you want it to stay in the right position based the background art, you might find more luck using standard config.lua:
application = { content = { width = 360, height = 480, scale = "letterbox", xAlign = "center", yAlign = "center", imageSuffix = { ["@2x"] = 1.5, ["@4x"] = 3.0, }, }, }
In this example, the 320x480 content area will be centered on the screen and you will have margins that are outside of that area. For instance on the iPad, your top, left won’t be 0, 0, but -20, -16. The bottom right will be 340, 496. But anything drawn at:
obj.x = 50
will be 50 points from that fixed 320x480 area that’s centered over your background. You can still place things outside of the 320x480 area, so setting something to obj.x = -10 will be 10 points left of the content area. On the iPhones, (and the android devices) this will be off screen, but for the iPad it will be on screen just closer to the edge.
Personally I prefer to always know that my 0, 0 is my top left and that display.contentWidth, display.contentHeight is my bottom right and give me the flexibility to position things relative to the actual edge of the screen or a relative distance from the center. It does take some extra thought to figure it out this way, but
bananaBasket.x = display.contentCenterX
will keep that basket centered. If you need the basket to always be 100 pixels from the center:
bananaBasket.y = display.contentCenterY + 100
but if you want it to always be 10 points from the bottom:
bananaBasket.y = display.contentHeight - 10 - (bananaBasket.height / 2)
Hope this helps
Rob