Академический Документы
Профессиональный Документы
Культура Документы
useful tasks
experimentation
"Community
Experience
Distilled"
Michelle M. Fernandez
$ 49.99 US
32.99 UK
Beginner's Guide
Corona is a software development kit to build mobile applications for iPhone, iPad, and Android devices.
ee
Sa
m
pl
e
Beginner's Guide
Michelle M. Fernandez
Chapter 7, Physics Falling Objects, covers how to implement the Box2D engine
in Corona SDK using display objects. You will be able to customize body construction
and work with the physical behavior of falling objects. In this chapter, we'll apply the
uses of dynamic/static bodies and explain the purpose of post collisions.
Chapter 8, Operation Composer, discusses how to manage all your game scenes
with Composer API. We'll also go into detail on menu design, such as creating
a pause menu and main menu. In addition, you'll learn how to save high scores
within your game.
Chapter 9, Handling Multiple Devices and Networking Your Apps, provides
information about integrating your applications with social networks such
as Twitter or Facebook. This will enable your app to reach a bigger
audience globally.
Chapter 10, Optimizing, Testing, and Shipping Your Games, explains the application
submission process for both iOS and Android devices. This chapter will guide you on
how to set up a distribution provisioning profile for the Apple App Store and manage
your app information in iTunes Connect. Android developers will learn how to sign
their applications for publication so they can be submitted to the Google Play Store.
Chapter 11, Implementing In-App Purchases, covers monetization of your game
by creating consumable, nonconsumable, or subscription purchases. You will apply
for In-App Purchases in the Apple App Store using Corona's store module. We'll take
a look at testing purchases on a device to check whether transactions have been applied
using the Sandbox environment.
Appendix, Pop Quiz Answers, covers all the answers enlisted
in the pop quiz sections of the book.
[1]
If you are installing Corona for Mac OS X, be sure that your system has the following features:
If you are running Microso Windows, be sure that your system has the following features:
1 GB of RAM (minimum)
OpenGL 2.1 or higher graphics system (available in most modern Windows systems)
The Android SDK is not required to create Android device builds with Corona on
Mac or Windows
1.
2.
The file extension for any Mac program should end in .dmg; this is known as an
Apple disk image. Once you've downloaded the disk image, double-click on the disk
image file to mount it. The name should be similar to CoronaSDK-XXXX.XXXX.
dmg. Once it is loaded, you should see the mounted disk image folder, as shown in
the following screenshot:
[2]
Chapter 1
3.
Next, drag the CoronaSDK folder into the Applications folder. This will copy the
contents of the Corona folder into /Applications. You will be prompted to enter
an administrator password if you are not the main administrator of the account.
You will be able to see the CoronaSDK folder in /Applications once it has been
successfully installed. For easy access to the folder contents, create an alias by
dragging the CoronaSDK folder to the dock of your Mac desktop:
[3]
First- me Corona SDK users will have to perform a quick and easy one- me authoriza on
process before it is accessible. You must be connected to the Internet to complete the
authoriza on process.
1.
2.
3.
Upon successful login, you will get a confirma on dialog to show that the SDK is
ready to use:
[4]
Chapter 1
4.
Click on the Con nue bu on, and you'll be presented with the Welcome to
Corona screen:
1.
2.
The file extension for the Windows version of Corona should end in .msi,
which is known as a Windows Installer, a component of Windows made to install
programs by Microso . Double-click on the file. The filename should be similar
to CoronaSDK.msi.
3.
[5]
4.
Corona will be installed directly into your Programs folder by default. On Microso
Windows, select Corona Simulator from the list of programs in your Start menu
or double-click on the Corona icon on the desktop. Upon successful ac va on,
you should be greeted with the following screen:
5.
The process to ac vate the SDK should be the same as the Mac procedure once you
launch Corona for the very first me.
If you run into issues with images not displaying properly, check to
see whether you're using an up-to-date OpenGL graphics driver,
2.1 or higher.
Be aware that Corona SDK on Windows can only build for Android
devices, not for iOS devices (iPhone, iPad, or iPod Touch). A Mac
can build not only for iOS, but also for Android devices in Corona.
6.
To create device builds, you need to install Java 6 SDK on your PC. You will need to
go to the Oracle website at http://www.oracle.com/technetwork/java/
javasebusiness/downloads/java-archive-downloads-javase6-419409.
html for the JDK download and click on the Java SE Development Kit 6u45 link.
7.
On the next page, select the Accept License Agreement radio bu on and then
click on the Windows x86 link to download the installer. You will be asked to log
in or create a user account on the Oracle website if you don't already have one.
8.
As soon as the JDK is downloaded, run the installer. Once installed, you'll be able
to create device builds for Android on your PC.
[6]
Chapter 1
Corona terminal: This launches the Corona simulator and opens a terminal
window to display error/warning messages and print() statements. It is
very helpful to debug your code, but is only available on a Mac.
Simulator: This has the same proper es as the Corona terminal, but is called
from the command line and is only available on a Mac.
Sample code: This is a set of sample applica ons to get you started with Corona.
It contains code and art assets to work with.
The Corona SDK window opens automa cally when you launch the simulator. You can open
a Corona project in the simulator, create a device build for tes ng or distribu on, and view
some example games and apps to get yourself familiar with the SDK.
[7]
1.
2.
Chapter 1
Outlaw (http://outlawgametools.com/outlaw-code-editor-andproject-manager/)
Any text editor, such as TextEdit for Mac or Notepad for Windows, that is already included
in the opera ng system works as well, but it'll be easier to work with one that is designed
for programming. For Corona, using an editor that supports the Lua syntax highligh ng will
work the best when coding. Syntax highligh ng adds forma ng a ributes to keywords and
punctua on in a way that makes it easier for the reader to separate code from text.
Developing on devices
It is not necessary to download Apple's developer kit, Xcode, or the Android SDK if you only
want to use the Corona simulator. In order to build and test your code on an iOS device
(iPhone, iPod Touch, and iPad), you will need to sign up as an Apple developer and create
and download the provisioning profiles. If you want to develop on Android, you don't need
to download the Android SDK unless you want to use the ADB tool to help with installing
builds and viewing debug messages.
The Corona SDK starter version allows you to build Adhoc (for iOS) and debug builds
(Android) for tes ng on your own devices. Corona Pro users also get the benefit of special
features, such as access to daily builds, premium features, all plugins, and premium support.
[9]
1.
Click on the Enroll Now bu on and follow Apple's instruc ons to complete the
process. When adding a program, select iOS Developer Program.
2.
When you have completed your enrollment, click on the iOS link under the sec on
marked Dev Centers.
3.
Scroll down to the Downloads sec on and download the current Xcode, or you can
download Xcode from the Mac App Store.
4.
[ 10 ]
Chapter 1
5.
A er you have entered your creden als, click on the OK bu on to complete the
installa on. You will see the following screen:
6.
When you have installed the Xcode developer tools, you can access the
documenta on by launching Xcode and choosing any of the items in the
Help menu. Developer applica ons such as Xcode and Instruments are
installed in /Applications/Xcode. You can drag these app icons to your
dock for convenient accessibility.
[ 11 ]
1.
Open your preferred text editor and type the following lines:
textObject = display.newText( "Hello World!", 160, 80,
native.systemFont, 36 )
textObject: setFillColor ( 1, 1, 1 )
2.
Next, create a folder on your desktop called Hello World. Save the preceding
text as a file named main.lua to the loca on of your project folder.
3.
Launch Corona. You will be greeted with the Corona SDK screen. Click on Open and
navigate to the Hello World folder you just created. You should see your main.
lua file in this folder:
[ 12 ]
Chapter 1
4.
On a Mac, click on the Open bu on. On Windows, select the main.lua file and click
on the Open bu on. You'll see your new program running in the Corona simulator:
[ 13 ]
1.
2.
Save your file and go back to the Corona simulator. The simulator will detect a change
from your file and automa cally relaunch with the changes. If the simulator doesn't
relaunch automa cally upon saving your file, press Command + R (Mac) / Ctrl + R
(Windows). You will see the following output on the screen:
[ 14 ]
Chapter 1
As you con nue learning more Corona func ons, you'll no ce that some of
the text values will be op onal. In this case, we need to use five values.
1.
2.
Be sure to save your main.lua file a er making any altera ons; then, press
Command + R (Mac) / Ctrl + R (Windows) in Corona to relaunch the simulator
to view the new font. If you're using a Mac, usually, the simulator automa cally
relaunches a er saving your file, or it may ask you if you want to relaunch the
program. You can see the new font in the simulator:
[ 15 ]
[ 16 ]
Chapter 1
1.
[ 17 ]
2.
In the User Email Address field, type in the e-mail address you used when you
registered as an iOS developer. For Common Name, enter your name or team name.
Make sure that the name entered matches the informa on that was submi ed when
you registered as an iOS developer. The CA Email Address field does not need to be
filled in, so you can leave it blank. We are not e-mailing the cer ficate to a Cer ficate
Authority (CA). Check Saved to disk and Let me specify key pair informa on. When
you click on Con nue, you will be asked to choose a save loca on. Save your file at a
des na on where you can locate it easily, such as your desktop.
[ 18 ]
Chapter 1
3.
In the following window, make sure that 2048 bits is selected for the Key Size and
RSA for the Algorithm, and then click on Con nue. This will generate the key and
save it to the loca on you specified. Click on Done in the next window.
[ 19 ]
4.
5.
Click on the Choose File bu on and locate your cer ficate file that you saved to
your desktop, and then, click on the Generate bu on.
6.
Upon hi ng Generate, you will get the e-mail no fica on you specified in the
CA request form from Keychain Access, or you can download it directly from the
developer portal. The person who created the cer ficate will get this e-mail and
can approve the request by hi ng the Approve bu on.
[ 20 ]
Chapter 1
7.
Click on the Download bu on and save the cer ficate to a loca on that is easy
to find. Once this is completed, double-click on the file, and the cer ficate will be
added automa cally in the Keychain Access.
[ 21 ]
Xcode
To find out your device's UDID, connect your device to your Mac and open Xcode. In Xcode,
navigate to the menu bar, select Window, and then click on Organizer. The 40 hex character
string in the Iden fier field is your device's UDID. Once the Organizer window is open, you
should see the name of your device in the Devices list on the le -hand side. Click on it and
select the iden fier with your mouse, copying it to the clipboard.
Usually, when you connect a device to Organizer for the first me, you'll receive a bu on
no fica on that says Use for Development. Select it and Xcode will do most of the
provisioning work for your device in the iOS Provisioning Portal.
[ 22 ]
Chapter 1
iTunes
With your device connected, open iTunes and click on your device in the device list. Select
the Summary tab. Click on the Serial Number label to show the Iden fier field and the
40-character UDID. Press Command + C to copy the UDID to your clipboard.
1.
Select Devices in the Developer Portal and click on the + icon to register a new
device. Select the Register Device radio bu on to register one device.
2.
Create a name for your device in the Name field and put your device's UDID in
the UDID field by pressing Command + V to paste the number you have saved
on the clipboard.
[ 23 ]
3.
Click on Con nue when you are done and click on Register once you have
verified the device informa on.
[ 24 ]
Chapter 1
1.
Click on App IDs in the Iden fiers sec on of the portal and select the + icon.
2.
3.
Fill out the App ID Descrip on field with the name of your applica on.
You are already assigned an Apple ID Prefix (also known as a Team ID).
[ 25 ]
4.
In the App ID Sux field, specify a unique iden fier for your app. It is up to
you how you want to iden fy your app, but it is recommended that you use
the reverse-domain style string, that is, com.domainname.appname. Click on
Con nue and then on Submit to create your App ID.
You can create a wildcard character in the bundle iden fier that you can share
among a suite of applica ons using the same Keychain access. To do this,
simply create a single App ID with an asterisk (*) at the end. You would place
this in the field for the bundle iden fier either by itself or at the end of your
string, for example, com.domainname.*. More informa on on this topic can
be found in the App IDs sec on of the iOS Provisioning Portal at https://
developer.apple.com/ios/manage/bundles/howto.action.
Provisioning profiles
A provisioning profile is a collec on of digital en es that uniquely es apps and devices to
an authorized iOS Development Team and enables a device to be used to test a par cular app.
Provisioning profiles define the rela onship between apps, devices, and development teams.
They need to be defined for both the development and distribu on aspects of an app.
[ 26 ]
Chapter 1
1.
Select the iOS App Development radio bu on under the Development sec on
and then select Con nue.
2.
Select the App ID you created for your applica on in the pull-down menu and
click on Con nue.
3.
Select the cer ficate you wish to include in the provisioning profile and then
click on Con nue.
4.
5.
Select the devices you wish to authorize for this profile and click on Con nue.
Create a Profile Name and click on the Generate bu on when you are done:
[ 27 ]
6.
Click on the Download bu on. While the file is downloading, launch Xcode
if it's not already open and press Shi + Command + 2 on the keyboard to
open Organizer.
7.
Under Library, select the Provisioning Profiles sec on. Drag your downloaded
.mobileprovision file to the Organizer window. This will automa cally copy
your .mobileprovision file to the proper directory.
Application icon
Currently, our app has no icon image to display on the device. By default, if there is no
icon image set for the applica on, you will see a light gray box displayed along with your
applica on name below it once the build has been loaded to your device. So, launch your
preferred crea ve developmental tool and let's create a simple image.
[ 28 ]
Chapter 1
The applica on icon for standard resolu on iPad2 or iPad mini image file is 76 x 76 px
PNG. The image should always be saved as Icon.png and must be located in your current
project folder. iPhone/iPod touch devices that support re na display need an addi onal
high resolu on 120 x 120 px and iPad or iPad mini have an icon of 152 x 152 px named as
Icon@2x.png.
The contents of your current project folder should look like this:
Hello World/
Icon.png
Icon@2x.png
main.lua
In order to distribute your app, the App Store requires a 1024 x 1024 pixel version of the
icon. It is best to create your icon at a higher resolu on first. Refer to the Apple iOS Human
Interface Guidelines for the latest ocial App Store requirements at http://developer.
apple.com/library/ios/#documentation/userexperience/conceptual/
mobilehig/Introduction/Introduction.html.
Crea ng an applica on icon is a visual representa on of your applica on name. You will
be able to view the icon on your device once you compile a build together. The icon is
also the image that launches your applica on.
1.
2.
[ 29 ]
3.
4.
Create a name for your app in the Applica on Name field. We can keep the same
name, Hello World. In the Version field, keep the number at 1.0. In order to
test the app in the Xcode simulator, select Xcode Simulator from the Build For
drop-down menu. If you want to build for the device, choose Device to build an app
bundle. Next, select the target device (iPhone or iPad) from the Supported Devices
drop-down menu. From the Code Signing Iden ty drop-down menu, choose the
provisioning file you created for the specified devices you are building for. It is the
same name as Profile Name in the iOS Provisioning Portal on the Apple developer
website. In the Save to folder sec on, click on Browse and choose where you
would like your applica on to be saved.
If all the informa on has been confirmed in the dialog box, click on the Build bu on.
It is more convenient to set your applica on to save on the Desktop;
this way, it is easy to find.
[ 30 ]
Chapter 1
[ 31 ]
Another way to install your app onto your device is to use Xcode, since it provides a
convenient method to install iOS device applica ons. Perform the following steps:
1.
With the device connected, open Xcode's Organizer from the menu bar by going
to Window | Organizer and navigate to your connected device under the Devices
list on the le -hand side.
2.
3.
Simply drag your build file and drop it into the Applica ons area of the Organizer
window, and it will automa cally install on your device.
[ 32 ]
Chapter 1
1.
2.
[ 33 ]
3.
Once your applica on is running in the simulator, go to the Corona Simulator menu
bar and navigate to File | Build For | Android (Windows) / Shi + Command + B on
your keyboard (Mac). The following dialog box will appear:
4.
Create a name for your app in the Applica on Name field. We can keep the same
name, Hello World. In the Version Code field, set the number to 1 if that is not
already the default number. This specific field must always be an integer and is not
visible to users. In the Version Name field, keep the number at 1.0. This a ribute is
the string shown to users. In the Package field, you will need to specify a name that
uses the tradi onal Java scheme, which is basically the reverse format of your domain
name; for example, com.mycompany.app.helloworld would work as a package
name. Project Path shows the loca on of your project folder. Minimum SDK Version
currently supports Android 2.3.3 and newer devices running the ArmV7 processor.
In the Target App Store pull-down menu, the default store can stay as Google Play.
In the Keystore field, you will be signing your build with the Debug keystore that is
already provided in Corona. In the Key Alias field, select androiddebugkey from the
pull-down menu if it's not selected. In the Save to Folder sec on, click on Browse and
choose where you'd like your applica on to be saved to.
[ 34 ]
Chapter 1
5.
If all the informa on has been confirmed in the dialog box, click on the Build bu on.
For more informa on on Java package names, see the sec on on Unique
Package Names in the Java documenta on at http://java.sun.com/
docs/books/jls/third_edition/html/packages.html#40169.
1.
Download the Dropbox installer and install it on your computer. Also, download
the mobile app from the Google Play Store (which is also free) on your device and
install it.
2.
Log in to your Dropbox account on your computer and mobile device. From your
computer, upload your Hello World.apk file.
3.
Once it has finished uploading, go to the Dropbox app on your device and select
your Hello World.apk file. You will be greeted with a screen that will ask you
if you want to install the applica on. Select the Install bu on. Assuming that it
installs correctly, another screen will appear saying Applica on installed, and you
can launch your Hello World app by pressing the Open bu on that is available.
[ 35 ]
Another method to upload an .apk file onto your device is to transfer it to an SD card via the
USB interface. If your device doesn't come with some kind of file manager applica on, a great
one you can download from the Google Play Store is ASTRO File Manager, which can be found
at https://play.google.com/store/apps/details?id=com.metago.astro. You can
always do a normal search for the preceding app or similar apk installers through the Google
Play app on your device. To transfer the .apk file to the SD card, perform the following steps:
1.
In your device's Se ngs, select Applica ons and then select Development.
Tap on USB Debugging if the mode is not ac ve.
2.
Go back a couple of screens to the Applica ons sec on. Enable Unknown Sources
if it is not already ac ve. This will allow you to install any non-market applica on
(that is, debug builds). Select the home bu on on your device when done.
3.
Connect the device to your computer with a USB cable. You will see a new
no fica on that a new drive has connected to your PC or Mac. Access the SD
drive and create a new folder. Name the folder to something you can iden fy
easily for your Android builds. Drag and drop your Hello World.apk file from
the desktop to the folder.
4.
Eject the drive from your desktop and disconnect your device from the USB cable.
Launch ASTRO File Manager or use whichever app you decided to download from
the Google Play Store. In ASTRO, select File Manager, search for the folder you
added to your SD card, and select it. You will see your Hello World.apk file.
Select the file, and a prompt will appear asking you to install it. Select the Install
bu on, and you should see your Hello World applica on appear in the Apps
folder of your device.
[ 36 ]
Chapter 1
One of the easiest methods is through Gmail. If you don't already have a Gmail
account, create one at https://mail.google.com/. Perform the following
steps to send the .apk file on your Gmail account:
1.
Log in to your account, compose a new e-mail, and a ach your Hello World.apk
file to the message.
2.
3.
Address the recipient of the message to your own e-mail address and send it.
On your Android device, make sure you have your e-mail account linked. As soon
as you receive the message, open the e-mail. You're given the op on to install
the applica on on your device. There will be an Install bu on or something
similar displayed.
[ 37 ]
Q2. How many iOS devices can you use for development in the iPhone Developer Program?
1. 50.
2. 75.
3. 5.
4. 100.
Q3. What does the version code have to be when building for Android in Corona SDK?
1. A string.
2. An integer.
3. It has to follow the Java scheme format.
4. None of the above.
Summary
In this chapter, we covered some of the necessary tools needed to start developing
applica ons for Corona SDK. Whether you are working on a Mac OS X or Microso
Windows, you will no ce the similari es in working on both opera ng systems and
how simple it is to run the Corona SDK.
To further familiarize yourself with Corona, try doing the following:
Take me to look into the sample codes provided by Corona to view the capabili es
of the SDK
Feel free to alter any of the sample codes to your liking to get a be er
understanding of programming in Lua
Now that you understand the process of how to display objects in Corona, we'll be able
to dive into other func ons that will help create an opera onal mobile game.
In the next chapter, we'll look at further details of the Lua programming language, and
you will learn simple coding techniques that are similar to the sample code in Corona.
You will get a be er understanding of the Lua syntax and no ce how fast and easy it is
to learn compared to other programming languages. So, let's get started!
[ 38 ]
www.PacktPub.com
Stay Connected: