34,79 €
iOS is an operating system for Apple manufactured phones and tablets. Mobile gaming is one of the fastest-growing industries, and compatibility with iOS is now becoming the norm for game developers. SpriteKit is part of the native SDK from Apple, and enables developers to make simple entry into game development without unnecessary overhead and a long learning process. SpriteKit also provides other functionality that is useful for games, including basic sound playback support and physics simulation. In addition, Xcode provides built-in support for SpriteKit so that you can create complex special effects and texture atlases directly in Xcode. This combination of framework and tools makes SpriteKit a good choice for games and other apps that require similar kinds of animation.
Become a master in iOS game development through this fast and fun guide!
In the beginning, we’ll tell you everything you need to plan and design your game. You’ll then start developing your game through step-by-step instructions using the various built-in technologies of Xcode. From there on, we discuss how to deploy your game to the iOS App Store, as well as monetizing it to make more revenue. You will also learn advanced techniques to improve your game playing experience, including better multi-tasking, improved performance optimization, battery management, and more. To end the book off, we’ll show you how to update your game with different features, then port the update to the App Store.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 222
Veröffentlichungsjahr: 2015
Copyright © 2015 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(s), 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: December 2015
Production reference: 1181215
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78355-435-5
www.packtpub.com
Author
Miguel DeQuadros
Reviewers
Andrew Kenady
Sahil Ramani
Sladjan Trajkovic
Commissioning Editor
Kunal Parikh
Acquisition Editor
Tushar Gupta
Content Development Editor
Athira Laji
Technical Editor
Vivek Pala
Copy Editor
Pranjali Chury
Project Coordinator
Harshal Ved
Proofreader
Safis Editing
Indexer
Monica Ajmera Mehta
Graphics
Disha Haria
Production Coordinator
Nilesh Mohite
Cover Work
Nilesh Mohite
Miguel DeQuadros is a game developer and the founder of the independent development studio, Wurd Industries, based in Ontario, Canada. He has been developing iPhone games since the release of the App Store back at the exciting release of iOS 2.0. Since then, he has released 10 games and 1 entertainment app world-wide on the App Store with more to come from Wurd Industries.
He was originally interested in 3D animation and graphical design, which he focused on mainly in 2004. But, he then got the game development bug and has been developing iPhone apps since 2008, which also allows him to use his creativity and knowledge of 3D animation for cut scenes and videos within his apps, and he is loving every minute of it. Starting from his first project, Toy Tennis, back in 2008, down to his current project, SpaceRoads, for PC, Mac, Wii U, and other platforms, he continues to develop high-quality apps and games alike. Moving away from simple game development tools, he now primarily uses Unity3D, 3D Studio Max, and the Unreal Engine for his current project in an aim to create very high-quality games.
His games can be seen on the App Store on iOS, Steam Greenlight, Amazon, and IndieCity, and of course on his website, www.wurdindustries.com. His games have been reviewed on YouTube by Action Soup Studios, and you can also find his interviews there.
I would like to thank my dad, John, even though he called me every two seconds to see how my book was going; his wife, Lucy; my brother and sister in-law, Johnny and Katie; my best friends, Brandon and Kaleb; and everyone else who has been there through everything. A very special thanks to my wonderful wife, Joanne, for encouraging me during the writing of this book (my wife asked me to thank Stella and Mimi, our dog and cat, as well. As if Stella didn't annoy me during the writing stage). Writing a book is very difficult, especially for your spouse and friends, as it does limit your association with them. I would also like to thank Packt Publishing and all the wonderful employees who helped me out both during the initial and final stages of this book, your professionalism and ability to clearly explain things also helped me a lot, thank you for everything. You made the production of the book a very smooth and enjoyable process!
Andrew Kenady is a game engineer from Kentucky. He holds a bachelor's degree in computer science from Western Kentucky University and has worked professionally in the game industry since his graduation in 2013. His published titles span multiple genres and platforms and include Battlepillars and Draw a Stickman: EPIC 2. He is currently working for a Tennessee-based tech company, NC2 Media, on new and promising confidential products for the mobile games sector.
In addition to working on this publication, he has previously reviewed the book iOS Game Programming Cookbook, Bhanu Birani and Chhavi Vaishnav, Packt Publishing.
Sladjan Trajkovic is a software engineer with a passion for game development. He has a master's degree in computer science and has been working in the software industry since 2007, where he began his career as a .NET consultant.
Nowadays, he works exclusively with the iOS platform, and he has been involved in several big name applications. He has also released two games on the App Store as an independent developer, Alien Defense Zone and Super Kicks. Currently, he is working on several new projects, both games and regular applications.
You can follow him on Twitter at twitter.com/SladanTrajkovic.
For support files and downloads related to your book, please visit www.PacktPub.com.
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.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.
Welcome! We all love game development and many of us dream of games we want to play, but alas, we never see them released. You are here to make that game, the one you've been planning, drawing, and dying to create for a long time. With the help of this book and with your awesome ideas, you will succeed in creating your dream game. In this book, you will learn how to use the free software available to you to create, develop, and release your awesome creations.
Welcome and enjoy the ride!
Chapter 1, What to Expect in Xcode and Game Development, covers how to become an Apple developer, how to download Xcode and the iOS development kit, and what to expect of the game development industry.
Chapter 2, Creating the Stuff, demonstrates how to use the various tools available to you to create sprites and various other images, sound effects, and even videos for your game.
Chapter 3, Blast Off! Starting with Development, talks about beginning our project. You will learn how to import various frameworks for our project and create our character and get him moving.
Chapter 4, Let's Keep Going! Adding More Functionality, discusses how to add some cool effects, such as particles for flames and rain, to our game now that our project is coming together.
Chapter 5, Bug Squashing – Testing and Debugging, covers testing our game and debugging it to ensure that there are no issues in it once we port our game.
Chapter 6, Making Our Game More Efficient, shows how we can make our game run better on all devices now that it is running flawlessly. By doing this, we will increase battery life, performance, and the overall user experience.
Chapter 7, Deploying and Monetizing, discusses how to show our game to the world and increase our revenue outlets by adding monetizing options.
Chapter 8, It's Too Dangerous to Go Alone, Take a Friend!, talks about making our game multiplayer after much planning, as we are now ready to update our game. We will incorporate multiplayer connectivity to find friends to play with!
For this book, all that you need is Xcode, which is Apple's software development kit for iOS, and any image creation software, such as Gimp or Photoshop.
This book is for all those who have a little experience of iOS development but really want to hone their skills.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <[email protected]>, and mention the book title via the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
You can contact us at <[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.
Welcome to the world of mobile game development! Whether you are a seasoned developer or a fresh new developer, you are in an exciting fast-paced industry. You have purchased this book expecting to master iOS game development, and that's exactly what you are going to do by the end of this book! However, you need to start somewhere, right? Let's see what will discuss in this chapter:
The mobile game development industry is so exciting! Get ready to take your first steps into game development. We will get you all signed up to be an Apple Developer, set up your Mac with the development environment, and take a tour of some of the features of Xcode and we are going to see what source files (the files that contain our code) look like. Then, we will discuss the game development market and how AMAZING it isn't. I'm kidding, it is a fun market!
Let's dive right into it, shall we?
As with many platforms (Mac, PC, Android, Blackberry, and Windows Mobile), iOS requires you to sign up to be a developer. Don't worry! It's super easy, simply go to developer.apple.com/ios/, where you will see the home page, as shown in the following screenshot:
Scroll down to find iOS Apps. Click on the iOS Apps button, and you will be greeted with the iOS Dev Center. Get used to this site as well as iTunes Connect, which we will cover later in this book —you will be using these sites a lot during your game development.
If you don't have a developer account, click on the register for free text so that you can get signed up for a new Apple ID. Another great thing about Apple is that their accounts are all linked, so when you register for a developer account, you can use your Apple ID. On the next screen, you will be asked to either sign in with your Apple ID or create a new one. Simply follow the prompts, fill in all your information, and pay the annual fee ($99 USD/ $119 CAD). When you are done, you should have access to the SDK. If you aren't redirected to the iOS Dev Center again, go to developer.apple.com/ios and scroll down to the Downloads section. As of the time of writing this book, the current version of Xcode is 6.2. Click on the Download button. You will be taken to a download screen; however, you will be ported over to the Mac AppStore. Xcode is now hosted on the Mac AppStore, which is a lot better because it automatically updates Xcode when needed. You will see the Xcode installation page, as shown in the following screenshot:
Click on the Get button to download Xcode. When it's done downloading (it will probably take a while unless you have fibre optic extreme Internet: It's 2.5 GB. The AppStore will automatically install Xcode for you.
Now, you should have a glittery new icon on your dock. When you open it, it may prompt you to do additional installation to support debugging or what not, go ahead and let it download any extra components needed, as shown in the following screenshot:
You will now be greeted with the Xcode welcome screen. From here, you can create new projects, open old ones, and even see a list of recent projects.
We will start setting up our game project, so click on Create a new Xcode project, and then the new project wizard will pop up. Here, you have a lot of empty project templates to choose from, but for this project, we will select the Game template under the iOS selection, under Application. Click on Game, and then click on Next. The next screen will ask for all the game information, which will be broken down like this:
Fill in all the fields of information as shown in the following screenshot:
To recap, for this project, we will select Objective-C, SpriteKit, and Universal. When you have filled in all the information, click on the Next button, and save your project in a location that's easy to remember.
Now you are in Xcode! Confused by what you see? Don't worry, it's actually pretty easy to navigate.
The following screenshot shows the general project settings, which is the first thing you see when you load an Xcode project:
For this project, we only want to support the landscape orientations; so, from the Deployment Info section under Device Orientation, deselect the Portrait option, and leave the two landscape orientations checked.
If you want, you can add in different capabilities for our game. Click on the Capabilities button on the topmost bar in the center of the screen, where you will see a ton of different options that you can add to your app. For example, we can add Game Center for leader boards and achievements, or we can add iCloud functionality by clicking the button from off to on. We can use iCloud to store game save data remotely, as shown in the following screenshot:
There are a lot of settings and variables that can be changed in the various sections of the topmost bar. We will get into some of them later on in this book.
Let's take a look around our project files to familiarize ourselves with the functions of the files. On the left-hand side bar, you will see .h and .m files, these are where all your programming goes.
The .h files are your header files, we will declare variables (such as integers and Booleans) and outlets (if we were building through the storyboard, we would declare buttons, labels, and a lot more. We would declare them in the header file, and connect them in the storyboard).
Don't worry, we are going to go into a lot more detail later on in this book.
The .m file is your main file where the majority of the coding goes. Declarations made in the header files are accessible as long as it's the same set of files, for example, you can access an integer from the AppDelegate.h file in the AppDelegate.m file. There are ways to access variables from other files, such as frameworks; or as long as you import the header files into the files you are working on. Again these are things we will discuss later. I don't want to confuse you at this point.
Let's look at the AppDelegate.h and AppDelegate.m files, starting with the .h file where you will see the following text:
There will be variations in the text that is commented (you can comment text out by typing // following the comment). You will know text is commented out when it is green in color.
Almost all code files will begin with importing files. The AppDelegate class seen in the preceding code shows #import <UIKit/UIkit.h>, which will allow you to access commands and functions from the UIKit headers. You can import any other header files here, for example, if you want to create an app with an option to make payments via PayPal, you can import the PayPal SDK, then import it into your file by typing #import <PayPal/PayPal.h> or whatever the file is that needs to be imported. When you start typing, Xcode will display a list of files that you can import.
We will now look at the next line, that is, @interface AppDelegate : UIResponder <UIApplicationDelegate>. This will vary depending on the type of interface you are working with (whether you are working with the app delegate, a view controller for our main menu, or on a PayPal payment view controller); it can be an ApplicationDelegate method in this file, or it can be a UIViewController or SKScene method. Again, it depends on the type of interface you are working with. You will see variations of different interfaces throughout this book.
Finally, we will see the last highlighted line, that is, @property (strong, nonatomic) UIWindow *window;. This is where your declarations will go. This line declares the app window. Properties are declarations of various items we use within our classes. For example, a property can be an integer, a Boolean, a window (as mentioned earlier), or even a button.
Finally, we have the @end line, which is simply the end of the file.
Now, let's look at the .m file:
In this file, you will call various functions when the application reaches certain states. If you read through some of the functions, you will see commented out text (to comment out text type // before the line of code) on what each state does, like when the application is terminated, or when it enters the background. With these functions, you can save data, log information, or even pause the game.
Seems fairly simple, right? Once you get the hang of things, it really is!
We will now have to add our developer account to the Xcode accounts preferences. This makes signing certificates and provisioning profiles much easier.
To add your account, click on Xcode in the topmost bar (where you see file, edit and all that fun stuff), then click on Preferences. Alternatively, you can press CMD+, for quick access to the menu.
When the preferences window appears, click on the Accounts tab, which is the second tab in the window.
In the lower-left corner of the window, click on the + button to add an account. When the drop-down menu appears, select Add Apple ID.
