Preface
There has never been a better time to be a game developer. The App Store provides a unique opportunity to distribute your ideas to a massive audience. Also, now Swift 3 has arrived! Apple's Swift language is maturing and hitting its stride in version 3. Whether you are new to game development or looking to add to your expertise, I think you will enjoy making games with Swift.
With this book, my goal is to share a fundamental knowledge of Swift and SpriteKit. We will work through a complete example game so that you learn every step of the Swift development process. Once you finish this text, you will be comfortable designing and publishing your own game ideas to the App Store from start to finish.
Please reach out to me for any questions and share your game creations:
E-mail: [email protected]
Twitter: @sdothaney
The first chapter explores some of Swift’s best features. Let’s get started!
What this book covers
Chapter 1, Designing Games with Swift, introduces you to the best features of Swift, outlines what is new in Swift 3, helps you set up your development environment, and launches your first SpriteKit project.
Chapter 2, Sprites, Camera, Action!, teaches you the basics of drawing and animating with Swift. You will draw sprites, import textures into your project, and center the camera on the main character.
Chapter 3, Mix in the Physics, covers the physics simulation fundamentals: physics bodies, impulses, forces, gravity, collisions, and more.
Chapter 4, Adding Controls, explores the various methods of mobile game controls: device tilt and touch input. We will also improve the camera and core gameplay of our example game.
Chapter 5, Spawning Enemies, Coins, and Power-ups, introduces the cast of characters we use in our example game and shows you how to create custom classes for each NPC type.
Chapter 6, Generating a Never-Ending World, explores the SpriteKit scene editor, builds encounters for the example game, and creates a system to loop encounters endlessly.
Chapter 7, Implementing Collision Events, delves into advanced physics simulation topics and adds custom events when sprites collide.
Chapter 8, Polishing to a Shine – HUD, Parallax Backgrounds, Particles, and More,adds the extra fun that makes every game shine. In this chapter, you will learn to create parallax backgrounds, learn about SpriteKit’s particle emitters, and add a heads-up display overlay to your games.
Chapter 9, Adding Menus and Sounds, builds a basic menu system and illustrates two methods of playing sounds in your games.
Chapter 10, Standing Out in the Crowd with Advanced Features, shows you how to combine the techniques you have learned to build advanced gameplay systems.
Chapter 11, Choosing a Monetization Strategy, outlines the strategies available to indie developers who want to make money from their games.
Chapter 12, Integrating with Game Center, links our example game to the Apple Game Center for leaderboards, achievements, and friendly challenges.
Chapter 13, Ship It! Preparing for the App Store and Publication, covers the essentials of packaging your game and submitting it to the App Store.
What you need for this book
This book uses the Xcode IDE, version 8.2.1 (Swift 3). If you use a different version of Xcode, you will likely encounter syntax differences; Apple is constantly upgrading Swift’s syntax. You can use Xcode’s Edit > Convert > To Current Swift Syntax to update the code examples in this book to a newer version of Xcode.
Visit https://developer.apple.com/xcode/ to download Xcode.
You will need an Apple developer account to integrate your apps with the Game Center and submit your games to the App Store.
Who this book is for
If you wish to create and publish fun iOS games using Swift, this book is for you. You should be familiar with basic programming concepts. However, no prior game development or Apple ecosystem experience is required.
Conventions
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The compiler will expect your variables to be of a certain type (int
, string
, and so on) and will throw a compile-time error if you try to assign a value of a different type."
A block of code is set as follows:
import SpriteKit class GameScene: SKScene { override func didMove(to view: SKView) { } }
New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Launch Xcode and navigate to File | New | Project."
Note
Warnings or important notes appear in a box like this.
Tip
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply e-mail [email protected], and mention the book's title in 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 at www.packtpub.com/authors.
Customer support
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.
Downloading the example code
You can download the example code files for this book 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.
You can download the code files by following these steps:
Log in or register to our website using your e-mail address and password.
Hover the mouse pointer on the SUPPORT tab at the top.
Click on Code Downloads & Errata.
Enter the name of the book in the Search box.
Select the book for which you're looking to download the code files.
Choose from the drop-down menu where you purchased this book from.
Click on Code Download.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
WinRAR / 7-Zip for Windows
Zipeg / iZip / UnRarX for Mac
7-Zip / PeaZip for Linux
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/-Swift-3-Game-Development. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Downloading the color images of this book
We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/Swift3GameDevelopmentSecondEdition_ColorImages.pdf.
Errata
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 could 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 to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/supportand enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy
Piracy of copyrighted 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.
Questions
If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.