Corona SDK Game Developers Guide for Android* Devices

By Michael John Rylee, Published: 06/27/2014, Last Updated: 06/27/2014


Corona is a popular framework that can be used to rapidly develop cross platform mobile apps.  Apps are developed using the Corona SDK which is based on the Lua scripting language.  Corona has a vibrant community of developers creating apps which has led to many great tutorials about using Corona available already.  This blog takes a specific focus on Android gaming and shows how to get started developing some basic components for a game and installing it onto an Intel® Android* x86 device.  In particular, displaying graphics, using the physics engine, detecting collisions, handling gestures, playing sounds, user interface widgets, saving & restoring state, and building & launching the Android APK will be discussed.


Development Environment:

The recommended development environment is using the Corona Editor.  This editor is a combination of using the Sublime Text 2 Editor with a Corona Plugin.  This plugin allows running, debugging, setting breakpoints, and single stepping through code.  This is a nice development environment for developing with the Corona Simulator.  

To learn more and get started with the Corona Editor, please see the link below.


Displaying Images:

Displaying an image in corona can be accomplished in 1 line of code.  The image file name and screen coordinates are passed to the function.

local myBall = display.newImage("myBall.png", display.contentCenterX, 20)

To learn more about the display API's, please see the link below.


Using The Physics Engine:

Corona comes with a powerful physics engine that is easy to use.  In this example, a ball is put into motion that can bounce off each side of the screen.  

-- 1. Add required code for using the physics engine
local physics = require("physics")

-- 2. Add bumper images to each side of the screen
local topBumper = display.newImage("top.png", display.contentCenterX, 0)
local bottomBumper = display.newImage("bottom.png", display.contentCenterX, display.contentHeight)
local leftBumper = display.newImage("left.png", 20, display.contentCenterY)
local rightBumper = display.newImage("right.png", display.contentWidth-20, display.contentCenterY) 

-- 3. Assign a body with density, friction, and bounce characteristics to each bumper image
physics.addBody( topBumper, "static", {density=3.0, friction=0.5, bounce=0.6} )
physics.addBody( bottomBumper, "static", {density=3.0, friction=0.5, bounce=0.6} )
physics.addBody( leftBumper, "static", {density=3.0, friction=0.5, bounce=0.6} )
physics.addBody( rightBumper, "static", {density=3.0, friction=0.5, bounce=0.6} )

-- 4. Add the ball image to the screen
local myBall = display.newImage("myBall.png", display.contentCenterX, 20)

-- 5.  Assign a body with density, friction, and bounce characteristics to the ball
physics.addBody( myBall, {density=3.0, friction=0.5, bounce=1.0} )

-- 6. Set the gravity initial value
local gravity=4
physics.setGravity(0, gravity)

To learn more about the physics API's, please see the link below:


Detecting Collisions:

Corona makes it easy to detect object collisions.  In this example, when the ball collides with one of the bumpers, it is detected and a sound is played.

--1.  Implement the onBallCollision listener and play a sound when the collision begins
local function onBallCollision ( event )
      if ( event.phase == "began" ) then
          media.playSound( "bounce.mp3" )

--2.  Add runtime listener for the collision event
Runtime:addEventListener( "collision", onBallCollision )

To learn more about collision detection and media API's, please see the links below:


Handling Gestures:

Corona makes it easy to handle touch gestures.  In this example, a swipe up with a finger is used to increase the gravity and a swipe down with a finger is used to decrease the gravity.

--1.  Implement the onBallTouch listener and modify the gravity when an up or down finger swipe is detected on the ball
local function onBallTouch( event )    
      if ( event.phase == "moved" ) then
         if ( event.y > event.yStart) then
            gravity = gravity+1
            gravity = gravity-1

--2.  Add an event listener for when the ball is touched
myBall:addEventListener( "touch", onBallTouch )

To learn more about the touch API's, please see the link below:


User Interface Widgets:

Corona provides a rich collection of familiar widgets such as buttons, pickers, and sliders for building user interfaces.  In this example, a slider is used to change the gravity of the scene so the ball falls at a different rate.

-- 1. Add required code to use widgets
local widget = require( "widget" )

-- 2.  Implement the slider listener and modify the gravity
local function mySliderListener( event )
      gravity = gravity*(event.value/100)
      physics.setGravity( 0, gravity ) 

-- 3.  Declare the slider and provide the coordinates, width, initial value, and listener
local mySlider = widget.newSlider
    left = display.contentCenterX-80,
    top = 0,
    width = 150,
    value = 50,
    listener = mySliderListener

To learn more about the widget API's, please see the link below:


Saving & Restoring State:

Corona provides file read & write capability so that app state can be saved and restored for providing an optimal user experience.  In this example, the gravity set from the slider is saved and restored.

-- Saving:

-- 1.  Provide the file path
        local path = system.pathForFile( "myGameFile.txt", system.DocumentsDirectory )

-- 2.  Open the file for writing
        local file = path, "w" )

-- 3.  Write the gravity value to the file
        file:write( gravity )

-- 4.  Close the file
        io.close( file )
        file = nil

-- Restoring:

-- 1.  Provide the file path
        local path = system.pathForFile( "myGameFile.txt", system.DocumentsDirectory )

-- 2.  Open the file for reading
        local file = path, "r" )

-- 3.  Read the gravity value from the file
        gravity = file:read( "*a" );

-- 4. Close the file 
        io.close( file )
        file = nil

-- 5. Restore the gravity in the physics engine

To learn more about the io API's, please see the link below


Building the Android APK:

Corona uses a cloud based build environment to build the lua code into an Android APK.  To initiate a debug test build, simply click File->Build for Android and click the Build button.

To learn more about building and distributing Android APK's, please see the link below:


Launching the Android APK:

Launching the Android APK on an Intel® Android x86 device is easily accomplished by using the Android Debug Bridge(ADB).  ADB is part of the Android SDK that can be downloaded from  To install the APK onto the device, issue the following command from the command line:

adb install -r <appName.apk>

To learn more about installation, please see the link below:


Additional Links:


++This sample source code is released under the MIT License

Product and Performance Information


Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804