Corona Reference: Getting Started


Requirements and Installation

In order to use Corona on your machine, you'll need either:
  • Windows 8, 7, Vista, or XP, with a 1 GHz processor and at least 1 GB of RAM, or
  • Mac OS X 10.9 or later with the latest version of Xcode installed (available free from the App Store)

Subscriptions

You'll need a Corona subscription, which is now free. Click here to register with Corona. You will be permitted to install Corona on two machines per registered email address, though you can register multiple accounts if needed.

No other subscription or developer license is required to begin building your app. However, if you'd like to test your app on an Apple device, you will need to join the Apple Developer Program.

Other Software

In addition to Corona, you'll need a text editor. Any text editor is fine, but you may want to use an editor with a few extra features that will make writing, reading, and working with code a little easier. Below is a brief and woefully incomplete list of text editors you may want to try:
  • Notepad++ (Windows Only)
    A free and powerful replacement for the standard Notepad editor on Windows machines.
  • TextWrangler (Mac Only)
    This is a free but powerful text editor for the Mac (and is the editor I use for development). If you like TextWrangler, you may want to upgrade to BBEdit, from the same publisher (most of the paid features are related to web development, and would not be useful for our class).
  • Sublime Text (Mac, PC, Linux)
    A very popular and extremely flexible text editor, with many available plugins and features. A license is $70 (free trials are available), so this may not be a great choice for our class. However, if you'll be continuing to write code (in any language) in the future, it may be a worthwhile investment.
  • UltraEdit (Mac, PC, Linux)
    An $80 editor that bills itself as the world's best. One month free trial available.
  • Vim (Mac, PC, Linux)
    A free and highly configurable text editor. You'll need to spend some time getting this one set up to your liking, but if you're a developer, it's worth the learning curve.

Using Corona

After you've created an account with Corona, you'll need to install the SDK. You can choose to install the latest Public Release or the latest Daily Build. Click here to sign in and download Corona for your machine.

Now navigate to the folder where you installed Corona, and open the Corona Simulator. The first time you open the simulator, you'll need to be online. Enter your Corona account information to login. You'll only need to do this once on your own machine; in the labs, you'll have to sign in for each use.

From the Simulator menu, you'll be able to start a new project using a Corona template, or view sample projects that demonstrate basic features and techniques. Most of the time, we'll be creating projects from scratch, so that's what we'll do now. Using your text editor, create a file called "main" with extension "lua" - your file should appear as main.lua, not main.txt or main.txt.lua. You can save this file anywhere you'd like to, but make sure you remember where you saved it. For now, try saving the file on your desktop. Enter the following code into your file:
local firstText = display.newText( "Hello World!", display.contentWidth/2, display.contentHeight/2, system.nativeFont, display.contentWidth/8 )
and save (be sure to save frequently, and whenever you'd like to see an updated version of your app in the simulator).

Now go back to the simulator menu. Choose 'Open File', and find your main.lua file. Click to open. You should see the words "Hello World!" in white text on a black screen. If so, Corona is installed and working properly, and you've successfully linked your text file to Corona.

The Simulator

The Corona simulator allows you to see how your app will look, without having to actually build and install the app on a device. In addition, you'll be able to make sure your app looks as it should on a variety of devices, which is important when you consider the wide range of screen sizes and ratios available on mobile devices. Below are some useful simulator features to be aware of:

The File Menu

  • New Project... will open the main simulator start modal, where you can create a new project from a template, browse sample apps included with your Corona download, and find links to Corona's documentation.
  • Open... to open an existing file.
  • Relaunch must be used whenever you've updated the code for your app. You can set up the simulator to relaunch automatically when a change to the app's files is detected, but you can manually relaunch at any time.
  • Build is used in order to test on a device or submit to an app store. The build process is handled remotely on Corona's servers, so you'll need to be online to build. When the process is complete (using just a minute or two), you'll receive a single file that contains your app, ready to be uploaded to your tablet or phone. There's no need to use this until you're ready to install your app on an actual device.
  • Show Project Sandbox will take you to the folder on your machine that Corona has created for your app. Each app has its own sandbox, containing all relevant files. The sandbox structure helps protect your machine (you won't accidentally overwrite system files, for instance). You won't usually need to go here, but we'll make use of the sandbox folder when learning how to read and write to files.

The Window Menu

  • Zoom In and Zoom Out can be used to make the simulator larger or smaller; note that the text and images on the screen itself are not zoomed. This just allows you to closely inspect your app and resize the window to fit more comfortably on your monitor.
  • Center quickly centers the simulator window on your monitor.
  • View As allows you to choose from a wide range of available devices to test your app. Note that this feature is only there to help make sure your app looks great on all devices; apps may still perform differently on each device, so you'll want to test your app on as many devices as you can. However, the various simulator skins can get your app down to the 'fine tuning' level.

The Hardware Menu

  • Rotate Left and Rotate Right to check how your app behaves when the device is rotated. Ideally, apps should look good in all four 'orientations', though this is not feasible for all apps and is a lot of work. Games, for instance, generally only work in landscape orientation. However, you at least need two functioning orientations for acceptance into most app stores, and you can use this feature of the simulator to make sure everything is working properly.
  • Shake tests what happens if the device receives a shake. Events like shaking and rotating are picked up by the 'runtime listener', and you'll be able to create functions that decide what to do in these cases. A common use of the 'shake' event is a 'shake-to-shuffle' feature of an MP3 player. Make light use of these 'features' however - people generally do not appreciate having to violently shake their expensive and easy to drop mobile devices!
  • Suspend can be used to make sure your app behaves properly when the user receives a phone call, exits to another app without closing your app, or any other event that would cause your app to 'suspend'.