This is the latest article on config.lua:
http://coronalabs.com/blog/2013/09/10/modernizing-the-config-lua/
I remember reading the precursor to this and being a bit ‘eh?’, but now they’ve released a new article and I’m struggling to understand what the issue is with config.luas regarding screen resolutions.
In particular what are they trying to achieve with the variable set up?
They talk of doing this to enable using fullscreen backgrounds (of which they have several), but then you need to make your code work with variable sized windows (the idea of changing the resolution of an app just to match a background image strikes me as absurd).
I have what I believe to be a much simpler method, that works on any aspect ratio.
The core of the config.lua would be:
[lua]application =
{
content =
{
width = 320,
height = 480,
scale = “letterbox”,
xAlign = “left”,
yAlign = “top”,
}[/lua]
Naturally you’d add your image suffixes for content scaling as you want, and change the default resolution to whatever you want as the minimum area.
Now, how does this handle changing aspect ratios?
Well, it doesn’t directly, but there-in lies the power. What it will do is stick a 320x480 area in the top left of your device display, stretched as big as possible without overlapping the borders (so you might get borders on the right side, or the bottom).
So now what? Well, it is easy. Just add the following code to your main.lua:
If running a portrait app:
[lua]_W = math.floor( display.actualContentWidth + 0.5 )
_H = math.floor( display.actualContentHeight + 0.5 )[/lua]
If running a landscape app:
[lua]_W = math.floor( display.actualContentHeight + 0.5 )
_H = math.floor( display.actualContentWidth + 0.5 )[/lua]
And now your globals _W and _H are the ACTUAL number of pixels you have for width and height, so instead of doing display.contentWidth you’d use _W etc. And… that’s it really, it just works. Far simpler, and you are always working from at least one guaranteed size of axes.
I’ve been using this approach for ages now and never had any problems at all regardless of device resolution or aspect ratio, and I don’t really get all the fuss about complicated config.lua.
Would welcome feedback, as I can’t help feeling I’m missing something…