Introduction to Corona SDK: Easy Cross-Platform Development

Introduction to Corona SDK: Easy Cross-Platform Development

Tutorial Details
  • Technology: iOS + Android
  • Difficulty: Beginner
  • Completion Time: 30 Minutes

Corona SDK is an excellent option for any kind of mobile developer from beginner to advanced. This tutorial will introduce you to this easy-to-use cross-platform framework and show you how to start creating content for your preferred platform.


Related Corona SDK Tutorials:


What is Corona SDK

Beginning Corona Development

The official Corona website describes the SDK as follows:

“Corona is a fast and easy development tool for iPhone, iPad and Android games and applications.

Corona-powered apps run at 30 fps in as little as 300k, and the graphics and animation engine fully leverages OpenGL hardware acceleration.

The Corona SDK is the first in Ansca’s Corona family of products for creating high-performance multimedia graphically rich applications and games for the iPhone. With Corona, you can quickly create iPhone applications in a matter of hours. No Objective-C/Cocoa required, and no C++.”

Ansca is the company behind Corona, and this SDK allows developers to create fast and powerful cross-platform applications that have access to API’s other frameworks don’t, like the camera, GPS and Accelerometer.

Advantages

Beginning Corona Development

As mentioned before, Corona SDK offers plenty of features that make it a very reliable way to create applications. Some of these features are:

  • Native Application Development: Corona executable binaries are 100% Objective-C/C++, so you won’t have to worry about Apple iOS 4 new rules on using outside development tools. In fact, Corona needs Xcode to compile.
  • Automatic OpenGL-ES Integration: No need to call extensive classes or functions to create simple screen manipulations.
  • Cross-Platform Development: Corona can create apps for iOS (iPhone, iPod Touch, iPad) and Android devices.
  • Performance: Corona is optimized to make use of hardware-accelerated features, resulting in powerful performance in games and apps.
  • Device Features: Access device native controls and hardware, like camera, accelerometer, gps, etc.
  • Easy to Learn: Corona uses the Lua programming language, which is powerful and easy to learn.

Disadvantages

As Ansca is not officially a part of Apple or Android, there are certain things that may be not available in recent releases of the native SDKs. However, the people maintaining Corona are constantly adding new features as they become available. This is a problem for all cross-platform frameworks.

Some examples of features not yet supported in Corona include:

  • iAds
  • Songs/Playlist Access
  • Photo Libraries Access
  • MapKit
  • Custom Font Support
  • Push Notifications

Supported Devices

Beginning Corona Development

The largest advantage of Corona is that it allow you to work with one code base and produce products for many different devices.

Specifically, the Corona SDK will allow you to create apps for all iOS devices and Android devices.

Development with Lua

Beginning Corona Development

Corona uses the Lua programming language to create applications. Lua is a scriptitng language commonly used to develop games. It has a good amount of market adoption in the development community. Lua syntax can be compared to languages such as JavaScript or ActionScript 3, which makes it easy to learn.

You can find out more about Lua on the official website.

Using Corona SDK

In order to use Corona SDK as your development environment you need the following:

  • Mac OS X 10.5.6+ (If developing iPhone apps, an Intel based Mac is needed for testing and App Store submission)
  • 1 GB RAM
  • 50 MB of hard drive space

If you have a PPC based Mac, you can still create applications with Corona. However, you will only be able to test your apps in the Corona Simulator and won’t be able to sell them in the App Store because Corona needs the latest version of Xcode to compile all iPhone applications.

Download Corona SDK

To start developing, go to the Corona SDK website and download a 30 day free trial.

Beginning Corona Development

Lua Editors

Beginning Corona Development

At this time, Corona doesn’t come with an exclusive Lua editor, but there are some great editors already available that you can use:

Free:

  • Eclipse, using the Lua Eclipse plugin.
  • LuaEdit, LuaEdit is an IDE/Debugger/Script Editor designed for the version 5.1 of Lua.
  • NotePad++, a free source code editor which supports several programming languages, including Lua.
  • TextWrangler, a powerful general purpose text editor and Unix and server administrator’s tool.

Commercial:

  • TextMate, Available for Mac OS X only.
  • BBedit, a leading professional HTML and text editor for the Macintosh.
  • Decoda, a professional development environment for debugging Lua scripts in your applications.

Creating Your First Program

To get started with Corona, let’s begin with the classic Hello World application.

Open your prefered Lua editor and write the following code:

print("Hello World!")

Create a new Project folder named HelloWorld and save the file as main.lua. We’ll launch this app in the next steps.

Terminal

If you come from a C like environment you will know that the print method outputs a string to the screen, you can test it by double clicking the Corona Terminal in the Corona application folder and selecting the HelloWorld project using the Open dialog.

Beginning Corona Development

This will also open the Corona Simulator displaying an iPhone graphic with no content, this is because the print function only outputs to the Terminal, to see how to display text in the simulator continue to the next step.

Simulator

To access the simulator or actual device screen, we’ll need to make use of the Corona specific API’s.

In your main.lua file write the following and then run the program again:

local myTextField = display.newText("Hello World!", 1, 20, nil, 14);myTextField:setTextColor(255, 255, 255);

Beginning Corona Development

What’s Next

You have created your first iPhone/iPad/Android application using Corona SDK in just a few minutes! Of course, there’s still a long run to go if you want to build great and high quality applications, so stick around for more updates!

Here are some additional links that will help you in the process of learning Corona:

Conclusion

Corona is very powerful and easy to learn, and these facts make it an excellent way to start or continue your software development no matter what platform you are building for.

Thanks for reading this tutorial, I hope you’ve found it useful!

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • zunaid

    isnt it possible to use corona in windows?

    • http://www.facebook.com/oprufssor Lello Romano

      for compiling reason you need a mac

  • http://corona.com kevin

    i would love to see more of this

  • Vishal

    How do I run my program on actual iPhone as we do in XCode by targeting device as iPhone and not simulator?

    Thanks
    Vishal

  • Richard Chang

    Hi,

    This is very good for a complete newbie.

    I’m using Windows 7 32 bit and would like more info on the Editors:
    I don’t know how to use Eclipse … and the Lua editor doesn’t seem to have any updates in 2010/2011 ?

    Thanks for any help on the easiest IDE to use ( beside Notepad ) on Windows ?

    Richard

  • http://www.cutemachine.com Joe

    @Vishal Start your program in the Corona SDK simulator. Then in the menu choose File > Build > iOS …
    Select Build for Device. Corona will create the application in the folder you specify in the dialog. Then use the Xcode Organizer to install the app on your iDevice.

    @Richard You can use your favorite editor to develop apps with Corona SDK. I use Vim as it gives you all the niceties like syntax coloring for Lua, code folding, starting the simulator from within Vim, and much more. I have written a short post on my blog you might want to read.

    Hope this helps.

  • fr33

    Ok, so is possible to use Corona in Linux, whichever is the distro chosen like Ubuntu for instance, or any flavor that derivate or is relative to it?

    It would be awesome, since I have all the Android things installed with Eclipse in my linux Distro and don’t want to have to install all and configure the whole thing in Windows.

    I mean, if is possible to use Corona SDK in linux natively, without wine.

    But if It possible with wine and works great, that wouldn’t be a problem, still be functional.

    Thanks in advance,

    fr33
    fr334rtist

  • Jameel

    I need some help—
    I need to create score for game, then i need the application to tell add
    scores, i have tried everything and cannt find a way to do this, plz provide
    me some sample if you can so that it can make me undetstand better.
    pls help me.
    Thanks

    The below is the code ……………..

    display.setStatusBar (display.HiddenStatusBar)
    require (“physics”)

    function main()
    setUpPhysics()
    createWalls()
    createBricks()
    createBall()
    createPaddle()
    startGame()
    — createScore ()
    — createLevel ()
    — local score = 0
    — local scoreText
    — local levelText
    — local levelNum
    end

    function setUpPhysics()
    physics.start()
    physics.setGravity(0,0)
    end

    function createPaddle()
    local paddleWidth = 200
    local paddleHeight = 30

    local paddle = display.newRect( display.contentWidth /1 – paddleWidth /1, display.contentHeight -30, paddleWidth, paddleHeight )
    physics.addBody(paddle, “static”, {friction=0, bounce=1})
    local movePaddle = function(event)
    paddle.x = event.x
    end

    Runtime:addEventListener(“touch”, movePaddle)
    end

    function createBall()
    local ballRadius = 20
    ball = display.newCircle( display.contentWidth / 2, display.contentHeight / 2, ballRadius )
    physics.addBody(ball, “dynamic”, {friction=0, bounce = 1, radius=ballRadius})
    ball.collision = function(self, event)
    if(event.phase == “ended”) then
    if(event.other.type == “destructible”) then
    event.other:removeSelf()
    end
    if(event.other.type == “bottomWall”) then
    self:removeSelf()
    local onTimerComplete = function(event)
    createBall()
    startGame()
    end
    timer.performWithDelay(500, onTimerComplete , 1)
    end
    end
    end
    ball:addEventListener(“collision”, ball)
    end

    function startGame()
    ball:setLinearVelocity(200, 600)

    end
    function createBricks()
    local brickWidth = 60
    local brickHeight = 30
    local numOfRows = 6
    local numOfCols = 7
    local topLeft = {x= display.contentWidth / 2 – (brickWidth * numOfCols ) / 2, y= 50}
    local row
    local col
    for row = 0, numOfRows – 1 do
    for col = 0, numOfCols – 1 do

    –function createScore ()
    levelScore = display.newText(‘Score:0′, 50, 10, ‘akashi’, 30)
    levelScore:setTextColor(254, 203, 50)
    levelNum = display.newText(’1′, 540, 10, ‘akashi’, 30)
    levelNum:setTextColor(254,203,50)

    –end

    — function createLevel ()
    levelText = display.newText(‘Level:’, 460, 10, ‘akashi’, 30)
    levelText:setTextColor(254, 203, 50)
    levelNum = display.newText(’1′, 540, 10, ‘akashi’, 30)
    levelNum:setTextColor(254,203,50)
    –end

    –ball:addEventListener (“touch”, ball)

    – Create a brick
    local brick = display.newRect( topLeft.x + (col * brickWidth),
    topLeft.y + (row * brickHeight), brickWidth, brickHeight )
    brick:setFillColor(math.random(50, 255), math.random(50, 255), math.random(50, 255), 255)
    brick.type = “destructible”
    physics.addBody(brick, “static”, {friction=0, bounce = 1})
    end
    end
    end

    function createWalls()
    local wallThickness = 10
    – Left wall
    local wall = display.newRect( 0, 0, wallThickness, display.contentHeight )
    physics.addBody(wall, “static”, {friction=0, bounce = 1})
    – Top wall
    wall = display.newRect(0,0, display.contentWidth, wallThickness)
    physics.addBody(wall, “static”, {friction=0, bounce = 1})
    – Right wall
    wall = display.newRect(display.contentWidth – wallThickness, 0, wallThickness, display.contentHeight)
    physics.addBody(wall, “static”, {friction=0, bounce = 1})
    – Bottom wall
    wall = display.newRect(0, display.contentHeight – wallThickness, display.contentWidth, wallThickness)
    physics.addBody(wall, “static”, {friction=0, bounce = 1})
    wall.type = “bottomWall”

    end

    main ()

  • http://mikewillcen.webstarts.com/ MarciaCarlson

    I was very pleased to find this site.I wanted to thank you for this
    great read!! I definitely enjoying every little bit of it and I have you
    bookmarked to check out new stuff you post.