Thursday, 12 April 2012

Corona Hello World


Hello World

The best (only) way to learn how to use the Corona SDK is by writing an app. To do that we write programs in a language called Lua. In keeping with tradition, let's write a some Lua code that prints “Hello World”.
The big roadblock, here, is figuring out the details of how to actually use the Corona SDK to do this. Once you've got these details mastered, everything gets a lot easier.
So let's get started! What you'll need is a text editor to write your program in. Later, you'll save that file to a folder so that the Corona Simulator can run and show you the results.
In the text editor, type the following:
print( "Hello World" )
Then save it to a file called main.lua in some folder that's easy to locate. Generally, every program should have its own folder on your system.
To run the program, you need to launch the Corona Simulator. All Corona SDK files should be in the Corona folder in your Applications folder (see Getting Started Guide for more information on how to install the Corona SDK.)
The contents of the SDK will look something like the picture at right. Double-click on the icon for Corona Terminal (the circled icon below).
This will launch a Terminal window and bring up a file dialog. In the dialog, navigate to the folder containing your main.lua file and click the Open button.
At this point, you will see “Hello World” in the Terminal window:

You will also see a blank simulator window (right) that simulates what would display on the actual phone. In this case, the phone screen remains blank because we're told the program to output to the Terminal.
Let's explain how this program worked. The app launches from the file calledmain.lua. The simulator loads this file and follows the instructions contained inside. Generally, an app consists of statements and variables. Statements provide instructions on what operations and computations need to be done; variables store the values of these computations.
In this program, we use a function called print. A function is just a collection of statements that perform some task. You send inputs into the function calledparameters (or arguments). Some functions return results. In the case of print, all it does is output the arguments as strings to the Terminal.

Hello World
local textObject = display.newText( "Hello World!", 50, 50, native.systemFont, 24 )
textObject:setTextColor( 255,255,255 )


No comments:

Post a Comment