Skip to content

Instantly share code, notes, and snippets.

@pkoperek
Last active May 30, 2024 07:15
Show Gist options
  • Save pkoperek/11156473 to your computer and use it in GitHub Desktop.
Save pkoperek/11156473 to your computer and use it in GitHub Desktop.
ultimate config.lua for corona sdk
-- http://coronalabs.com/blog/2013/09/10/modernizing-the-config-lua/
-- calculate the aspect ratio of the device:
local aspectRatio = display.pixelHeight / display.pixelWidth
application = {
content = {
width = aspectRatio > 1.5 and 320 or math.ceil( 480 / aspectRatio ),
height = aspectRatio < 1.5 and 480 or math.ceil( 320 * aspectRatio ),
scale = "letterBox",
fps = 30,
imageSuffix = {
["@2x"] = 1.5,
["@4x"] = 3.0,
},
},
}
@XeduR
Copy link

XeduR commented Jun 24, 2021

A warning to anyone who finds this:

This config.lua configuration was written in August 2013, when Android apps were always guaranteed to always take the same space on the display (i.e. full screen). In Solar2D (formerly Corona SDK), the config.lua file is run when the app launches, so the display.pixelHeight and display.pixelWidth in this config.lua file are based on what the screen dimensions available to the app at that time.

However, in September 2013, with the release of Android 4.4 KitKat, Android apps could now use "immersive mode", which meant they they could hide the "virtual Android nav bar" that hadn't been a part of the display before. When the nav bar is hidden, the space available for the app on the screen changes. This means that if you do hide the nav bar, then the content area in your config.lua will no longer match the screen dimensions, which will lead to issues if you've written your app based on the assumption that those two will always match.

The available screen size can also change if using Android's multi-window feature or when building for Windows or MacOS, etc.


Solar2D handles all sized screens and screen updates well, but this is not the way to go about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment