Book Image

Corona SDK Mobile Game Development: Beginner's Guide

Book Image

Corona SDK Mobile Game Development: Beginner's Guide

Overview of this book

Corona SDK is the fastest and easiest way to create commercially successful cross platform mobile games. Just ask Robert Nay, a 14 year old who created Bubble Ball - downloaded three million times, famously knocking Angry Birds off the top spot. You don't need to be a programming veteran to create games using Corona. Corona SDK is the number one tool for creating fun, simple blockbuster games. Assuming no experience at all with programming or game development you will learn the basic foundations of Lua and Corona right through to creating several monetized games deployable to Android and Apple stores. You will begin with a crash course in Lua, the programming language underpinning the Corona SDK tool. After downloading and installing Corona and writing some simple code you will dive straight into game development. You will start by creating a simple breakout game with controls optimized for mobile. You will build on this by creating two more games incorporating different features such as falling physics. The book ends with a tutorial on social network integration, implementing in app purchase and most important of all monetizing and shipping your game to the Android and App stores.
Table of Contents (18 chapters)
Corona SDK Mobile Game Development Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface

Time for action – applying a new font name to your application


Now let's play around with the font name.

  1. Change the first line to the following code:

    textObject = display.newText( "Hello World!", 50, 40, "Times New Roman", 36 )
  2. Be sure to save your main.lua file after making any alterations, then press Command+R (Mac)/Ctrl+R (Windows) in Corona to re-launch the simulator to view the new font. If you're using a Mac, usually the simulator automatically re-launches after saving your file or it may ask you if you want to re-launch the program.

What just happened?

You have now made your first complete mobile application! What's even more amazing is that this is a completed iPhone, iPad, and Android application. This two-line program will actually install and run on your iOS/Android device if you were to create a build. You have now seen what the basic workflow in Corona is like.

If you take a look at line 2 in your main.lua file you will notice that setTextColor alters the color of the text for Hello World!.

Colors are made up of three sets of RGB numbers representing the amount of red, green, and blue contained within a color. They are displayed with three numbers with values ranging from 0 to 255. For example, the color black would be ( 0,0,0 ), blue would be ( 0,0,255 ), and the color white ( 255,255,255 ).

Continue playing around with different color values to see the different results. You can see the alterations to the code in the simulator when you save your main.lua file and re-launch Corona.

When you view the first line from the main.lua file you will notice that newText() is called by textObject, a name that is then used to reference the display text. The newText() function returns an object that will represent the text on the screen. newText is part of the display library.

When you want to access the display property of newText, type in display.newText. The two numbers after Hello World! control the horizontal and vertical positions of the text on the screen in pixels. The next item specifies the font. We used the name native.systemFont, which by default refers to the standard font on the current device. For example, the iPhone's default font is Helvetica. You can use any standard font name such as Times New Roman (used in the preceding example). The last number used is the font size.

Have a go hero – adding more text objects

Now that you're starting to get a taste of coding, try applying the following in your current project file:

  • Create a new display object using a different font and text color. Display it below the Hello World! text. Hint: Make sure your new text object has a different object name.

  • Continue changing values of the current display object, textObject. Alter the x and y, the coordinates, the string text, the font name, and even the font size.

  • While the object setTextColor( r,g,b) sets the color of the text, there is an optional parameter you can add that controls the opacity of the text. Try using the object setTextColor( r, g, b [, a]). The values available for a also range between 0 to 255 (255 is opaque, which is the default value). Observe the results of your text color.