Runtime configuration
All project files not only contain a main.lua
file but other .lua
and related assets as needed for your project. Some Corona projects are configured using a config.lua
file that is compiled into your project and accessed at runtime. This allows you to specify dynamic content scaling, dynamic content alignment, dynamic image resolution, frame rate control, and anti-aliasing all at the same time so that the output on every type of device is displayed similarly.
Dynamic content scaling
You can specify to Corona what the original screen size for your content is. Then allow it to scale your app to run on a device that has a different screen size to the original.
The following values should be used to scale content:
width
(number)—Screen resolution width of the original target device (in portrait orientation)height
(number)—Screen resolution height of the original target device (in portrait orientation)scale
(string)—Type of autoscaling from the following:none
—Dynamic content scaling turned offletterbox
—Uniformly scales up content as much as possiblezoomEven
—Scales up content uniformly to fill the screen, while keeping the aspect ratiozoomStretch
—Scales up content non-uniformly to fill the screen and will stretch it vertically or horizontally
Dynamic content alignment
Content that is dynamically scaled is already centered by default. You may find cases where you don't want the content to be centered. Devices such as the iPhone 3G and the Droid have completely different screen resolutions. In order for the content displayed on the Droid to match the iPhone 3G, the alignment needs to be adjusted so the content fills the entire screen without leaving any empty black screen space.
xAlign
: A string that specifies the alignment in the x-direction. The following values can be used:
left
center
(Default)right
yAlign
: A string that specifies the alignment in the y-direction. The following values can be used:
top
center
(Default)bottom
Dynamic image resolution
Corona allows you to swap in higher-resolution versions of your images to higher-resolution devices, without having to change your layout code. This is a case to consider if building for multiple devices with different screen resolutions.
An example where you want to display high-resolution images is on an iPhone 4 where the resolution is 640 x 960 pixels. It is double the resolution of the earlier iOS devices such as the iPod Touch 2G or the iPhone 3GS which both are 320 x 480 pixels. Scaling up the content from the iPhone 3GS to fit the iPhone 4 screen works, but the images will not be as crisp and will look a little fuzzy on the device.
Images of higher resolution can be swapped in for the iPhone 4 by adding a @2x
suffix to the end of filenames. For example, if your image filename is myImage.png
then your higher resolution filename should be myImage@2x.png
.
In your config.lua
file, a table named imageSuffix
needs to be added for the image naming convention and image resolutions to take effect. The config.lua
file resides in your project folder where all your other .lua
files and image files are stored. Look at the following example:
application = { content = { width = 320, height = 480, scale = "letterbox", imageSuffix = { ["@2x"] = 2, }, }, }
When calling your display objects, use display.newImageRect( [parentGroup,] filename [, baseDirectory] w, h )
instead of display.newImage()
. The target height and width need to be set to the dimensions of your base image.
Frame rate control and anti-aliasing
The frame rate is 30 fps (frames per second) by default. FPS refers to the speed at which the image is refreshed in games. 30 fps is the standard in mobile games, especially for older devices. You can set it to 60 fps when you add in the fps key. Using 60 fps makes your app run smoother. You can easily detect a life-like fluidity in the motion when it comes to running animations or collision detections.
Corona uses software anti-aliasing for vector objects. By default, it is turned off to improve the performance of the vector objects. You can turn it on by setting the antialias
key to true
.
See the following example:
application = { content = { fps = 60, antialias = true, }, }