Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Corona SDK Mobile Game Development: Beginner's Guide

You're reading from  Corona SDK Mobile Game Development: Beginner's Guide

Product type Book
Published in Mar 2015
Publisher
ISBN-13 9781783559343
Pages 372 pages
Edition 1st Edition
Languages
Author (1):
Michelle M Fernandez Michelle M Fernandez
Profile icon Michelle M Fernandez

Table of Contents (19) Chapters

Corona SDK Mobile Game Development Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Getting Started with Corona SDK 2. Lua Crash Course and the Corona Framework 3. Building Our First Game – Breakout 4. Game Controls 5. Animating Our Game 6. Playing Sounds and Music 7. Physics – Falling Objects 8. Operation Composer 9. Handling Multiple Devices and Networking Your Apps 10. Optimizing, Testing, and Shipping Your Games 11. Implementing In-App Purchases Pop Quiz Answers Index

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


Now, let's play around with the font name by performing the following steps:

  1. Change the first line to the following line of code:

    textObject = display.newText( "Hello World!", 160, 80, "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 relaunch the simulator to view the new font. If you're using a Mac, usually, the simulator automatically relaunches after saving your file, or it may ask you if you want to relaunch the program. You can see the new font in the simulator:

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 setFillColor alters the color of the text for Hello World!.

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

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 relaunch Corona.

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

When you want to access the display properties 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 that is 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 following these steps in your current project file:

  1. Create a new display object using a different font and text color. Ensure it displays below the Hello World! text. Make sure that your new display object has a different object name.

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

  3. While object:setFillColor( 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 object:setFillColor( r, g, b [, a] ). The values available for a also range between 0 to 1 (1 is opaque, which is the default value). Observe the results of your text color.

You have been reading a chapter from
Corona SDK Mobile Game Development: Beginner's Guide
Published in: Mar 2015 Publisher: ISBN-13: 9781783559343
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}