Corona SDK Application Design A quick and easy guide to creating your very own mobile apps with Corona SDK Daniel Williams BIRMINGHAM - MUMBAI Corona SDK Application Design Copyright © 2013 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: June 2013 Production Reference: 1060613 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-84969-736-1 www.packtpub.com Cover Image by Suresh Mogre ([email protected]) Credits Author Project Coordinator Daniel Williams Siddhant Shetty Reviewers Proofreader Mitch Allen Paul Hindle Predrag Končar Jamie Trinder Indexer Hemangini Bari Acquisition Editor Joanne Fitzpatrick Production Coordinator Nitesh Thakur Commissioning Editor Sruthi Kutty Cover Work Nitesh Thakur Technical Editors Prasad Dalvi Pushpak Poddar Saumya Kunder About the Author Daniel Williams is a web developer, mobile game developer, online specialist, and founder of That's So Panda (www.thatssopanda.com). Since starting his own mobile adventure with Corona SDK a couple of years ago, Daniel has released several app titles and has written several tutorials on www.thatssopanda.com for individuals just starting with Corona SDK. When he's not busy reading about the latest technology news or working on his latest app title, he can be found watching the latest movies, discovering new local restaurants, or playing video games. I would like to thank my wife, for always being my personal cheerleader. About the Reviewers Mitch Allen has worked on software projects for Lotus, IBM, Dragon, Nuance, Yahoo, and Intuit, as well as for a few startups. He specializes in everything from Enterprise Web Apps to Mobile. He has worked in Silicon Valley, Silicon Alley, and along Boston's Route 128. He currently resides in Western Pennsylvania. Previously, he has reviewed the book Corona SDK Mobile Game Development Beginner's Guide by Packt Publishing. For more information, please visit his website at http://mitchallen.com where he blogs about everything from mobile game development to robotics. Predrag Končar is a founder of Glyphed – a multidisciplinary research studio. His primary areas of interest are programming and combining technology and art. Predrag is also into robotics, image and audio processing, and interactive design, and he likes to spend his free time painting. In the last 12 years, he has worked as a Technical and Creative Director on many online projects, published over 40 online games, participated in the production of several iOS apps, and worked with Packt Publishing as a technical reviewer on the book Corona SDK Mobile Game Development Beginner's Guide. He has a strong background in ActionScript, Lua, MEL script, Maya, and Python. Predrag is also a member of MENSA and ACM SIGGRAPH. Jamie Trinder is the Technical Director for T and G Apps Ltd, who create mobile applications and games for multiple mobile platforms. Jamie has a background with various coding languages and has been a part of creating numerous mobile applications. Jamie uses Corona and Lua extensively from day to day and finds them invaluable tools for rapidly prototyping ideas for the company. www.PacktPub.com Support files, eBooks, discount offers and more You might want to visit www.PacktPub.com for support files and downloads related to your book. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. http://PacktLib.PacktPub.com Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books. Why Subscribe? • Fully searchable across every book published by Packt • Copy and paste, print and bookmark content • On demand and accessible via web browser Free Access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access. Table of Contents Preface 1 Chapter 1: Getting Started with Your Mobile Adventure 5 What is Corona SDK? 5 Prerequisites for Corona SDK 6 Downloading, installing, and using Corona SDK 7 Installing for Mac OS X 7 Installing for Microsoft Windows 8 Using Corona SDK 8 Summary 10 Chapter 2: Learning Lua 11 Using variables with Lua 11 Using the terminal 12 Expressions and operators 13 Arithmetic expressions 13 Comparison operators 13 Making decisions 14 The if-then statement 14 The if-then-else statement 15 Loops, loops, and loops 15 The for loop 16 The while loop 17 More flexibility with tables 17 Using functions 19 Summary 20 Table of Contents Chapter 3: Creating Your First App 21 Using a text editor 22 Notepad++ 23 Sublime Text 23 Corona-specific editors 23 Creating a new project 23 An introduction to Storyboard 26 The createScene function 27 The enterScene function 27 The exitScene function 28 The destroyScene function 28 Switching scenes 28 Destroying scenes 28 Using widgets 29 Starting with main.lua 31 view1.lua – about us 35 view2.lua – your BMI 38 view3.lua – contact us 46 config.lua – set up dynamic content resolution 49 App icons 50 Summary 51 Chapter 4: Creating a Puzzle App 53 A quick introduction to puzzle games 53 Downloading the starter kit 54 My Jigsaw Puzzle 54 build.settings 55 config.lua 56 main.lua 56 menu.lua 56 gameplay.lua 59 Getting local libraries 59 Creating variables 59 Creating display groups 61 The shuffle function 61 Creating the shuffle function 62 Dragging-and-dropping display objects 62 Creating the drag function 64 Summary 72 [ ii ] Table of Contents Chapter 5: Testing and Publishing 73 How to test your app 73 iOS 73 Android 74 Publishing your app 74 Publishing to Apple's App Store 74 Publishing to Google Play 75 Other resources and the Corona community 75 Appendix: Tools, Services, and Marketing 77 Third-party tools 77 Third-party services 78 Marketing tips 78 Index 81 [ iii ]