It is possible, but I don’t generally think smart config files are a good idea.
Why? Because, by changing the resolution in the config file dynamically, you can’t rely on knowing the content-resolution in your code. Thus all sizes, spacing,etc need to be determined programatically. This is a lot of work, error prone, and may result in ugly results in some cases.
Instead, I prefer to choose a single configuration and then accommodate that setup for all resolutions. While there is still some programmatic work here, it is significantly simpler and one can make fixed decisions on most layout and sizing.
For me, there are two exceptions:
-
Pixel Perfect Requirement - In some cases, you need to ensure sub-pixel rounding is minimized/avoided. To do this you can use this config.lua file (or a varation): https://github.com/Lerg/smartpixel-config-lua
2. Distinct Platforms - Sometimes, you know most of your users will be on mobile, but you also have a set of users on desktop. In the latter case, it can be difficult to make everything look great if you’ve put most of your thought into mobile. In this case, you may want to set up your app/game as follows:
- bifurcated config.lua - Selects one config for mobile devices and a different one for desktop.
- bifucated design - In critical sections of you app/game interface/layout you may execute entirely different code for very different layout designs. Again, one for mobile and the other for desktop.
Again, 99% of the time I make a single fixed resolution work on all platforms.
PS - Today, the biggest PITA for me has been the iPhone X and other super tall resolutions. Having to make a game look good and be accessible on both 640 x 960 and 1125 x 2436 is not fun.
PPS - This is the code for the pixel-perfect solution from Sergey.
-- Author: Lerg - spiralcodestudio.com -- GitHub: https://github.com/Lerg/smartpixel-config-lua -- SmartPixel config.lua -- Uses pixel perfect content scaling when possible local w, h = display.pixelWidth, display.pixelHeight local modes = {1, 1.5, 2, 3, 4, 6, 8} -- Scaling factors to try local contentW, contentH = 320, 480 -- Minimal size your content can fit in -- Try each mode and find the best one local \_w, \_h, \_m = w, h, 1 for i = 1, #modes do local m = modes[i] local lw, lh = w / m, h / m if lw \< contentW or lh \< contentH then break else \_w, \_h, \_m = lw, lh, m end end -- If scaling is not pixel perfect (between 1 and 2) - use letterbox if \_m \< 2 then local scale = math.max(contentW / w, contentH / h) \_w, \_h = w \* scale, h \* scale end application = { content = { width = \_w, height = \_h, scale = 'letterbox', fps = 60, imageSuffix = { ['@2x'] = 1.1, ['@4x'] = 2.1, } } } -- Uncomment to use the common content scaling --[[application = { content = { width = 320, height = 480, scale = 'letterbox', fps = 60, imageSuffix = { ['@2x'] = 1.1, ['@4x'] = 2.1, } } } --]]