Skip to content

Instantly share code, notes, and snippets.

@aarti
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aarti/a81cdf3bbdd249973243 to your computer and use it in GitHub Desktop.
Save aarti/a81cdf3bbdd249973243 to your computer and use it in GitHub Desktop.
Corona Simple config.lua supporting multiple devices
--http://forums.coronalabs.com/topic/37362-improvement-to-the-ultimate-configlua-file/
--The effect of that bit of math is to set the content width or height appropriately for letterbox scaling according to the aspect ratio of the device. Why is that good? Because the upper-left corner is now (0,0), and display.contentWidth and display.contentHeight now cover the entire screen. For example, on an iPhone 5, display.pixelHeight is 1136 and display.pixelHeight is 640. If you do the math, you'll see that it'll set width to 320 and height to 568.
-- It'll set the width and height appropriately for every single device, no matter what the resolution or aspect ratio. And there's no need to code into your config.lua different blocks for different devices.
--the upper-left corner isn't at (0,0). Instead, it's at (display.screenOriginX, display.screenOriginY)
local aspectRatio = display.pixelHeight/display.pixelWidth
application =
{
content =
{
width = aspectRatio>1.5 and 320 or 480/aspectRatio,
height = aspectRatio<1.5 and 480 or 320*aspectRatio,
scale = "letterbox",
fps = 60,
imageSuffix =
{
["@2x"] = 1.5,
["@4x"] = 3.0,
},
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment