I would recommend reading these two tutorial’s in order. The 2nd one builds upon the first one and the first one has information you need to understand background sizing and positioning:
http://www.coronalabs.com/blog/2012/12/04/the-ultimate-config-lua-file/
http://www.coronalabs.com/blog/2013/09/10/modernizing-the-config-lua/
The general principle is that you define a content area (what ever you want, it’s a virtual size) and using some tricks you can make that content area fit the shape of the device’s screen in question. But you have a constant size you work with. Then you build your art work so that it is sized right for the content area you defined and Corona SDK will do the rest.
Now there are a couple of different strategies to handle larger vs. smaller screen sizes.
- Use one sized image and let Corona SDK scale it up and down.
- Use multiple sized images that Corona SDK will pick from depending on the screen size.
Most people use the latter, because while it’s more work and means a larger bundle size when uploading your app, it has the trade off of being more memory efficient on low memory, low resolution devices as well has providing higher quality images for high resolution devices.
I’m going to use Apple devices just as a talking point because they make life easy. If you need to support a low-res device like an Apple iPhone 3 series, it has a screen size of 320 x 480. The new phones iPhone 4 and 5 are double that size at 640 x 960 (exactly double the pixels) and 640 x 1136 (this is where the automatic screen selection in those blogs come into play). So traditionally you would define your content area as 320x480 and build your art for that, but have a version that was twice as big typically with an @2x suffix on the name:
monster.png 50x50
monster@2x.png 100x100
With the right settings in your config.lua, Corona would detect that you were on a higher resolution screen and use the better graphic since scaling images up makes them fuzzy. Now thinking about the iPads. There is a 768x1024 screen and the retina displays which are exactly twice that size at 1536x2048. So the idea of the two images sort of still holds, but if you want to build one app that handles all four of those devices then we get into some additional problems. But if you think about it 640x and 768x are pretty close in size. You can use your @2x graphics for both of these devices since the scaling up/down isn’t that drastic. Then to support the big tablet screens you would then add an @4x graphic.
monster@4x.png 200x200
With all of this in place, you build your app for the 1x size, so your 50x50 monster will fit into your 320x480 content area and Corona handles everything else. When you factor in Android, the fact that the iPhone3/4, iPhone 5 and iPad families all have different screen shapes, this is where the automatic content area sizing kicks in. In the first blog post, there is a discussion on how to size your backgrounds so that they work regardless of the device. Don’t gloss over that part.
When you get into the 2nd part of the 2nd tutorial, we suggest that you break out of the mindset of device pixels and just pick a content area that works for you and your art. We also suggest that it’s time to no longer support the small devices and just let Corona SDK scale down to them and make the medium sized devices your base.
Rob