Build iOS Games with Sprite Kit
Unleash Your Imagination in Two Dimensions
by Jonathan Penn, Josh Smith
Version: P1.0 (July 2014)
Copyright 2014 The Pragmatic Programmers, LLC. This book is licensed tothe individual who purchased it. We don't copy-protect itbecause that would limit your ability to use it for yourown purposes. Please don't break this trustyou can use this across all of your devices but please do not share this copywith other members of your team, with friends, or via file sharing services. Thanks.
Dave & Andy.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g device are trademarks of The Pragmatic Programmers, LLC.
Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein.
Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at http://pragprog.com.
The team that produced this book includes:
Rebecca Gulick (editor)
Potomac Indexing, LLC (indexer)
Cathleen Small (copyeditor)
David J Kelly (typesetter)
Janet Furlow (producer)
Ellie Callahan (support)
For international rights, please contact .
For the Best Reading Experience...
We strongly recommend that you read this book with the publisher defaults setting enabled for your reading device or application. Certain formats and characters may not display correctly without this setting. Please refer to the instructions for your reader on how to enable the publisher defaults setting.
Table of Contents
Copyright 2014, The Pragmatic Bookshelf.
Early Praise for Build iOS Games with Sprite Kit
This book is your quickest path from creating a new Sprite Kit project in Xcode to shipping an iOS game. Joshua and Jonathan have a great deal of experience creating games with Sprite Kit and teaching the technology in their popular seminar. In this book they show you the fundamentals and help you avoid the gotchas.
Daniel H. Steinberg, Dim Sum Thinking |
I had never written a game before, but with hands-on practice, this book guided me through the basics of how to set up a Sprite Kit app. In detail, it covers how to progress from the basics up to advanced topics, like physics, textures, and frame-based animations. This book is a great way to dip your toes into the exciting new Sprite Kit framework.
Ash Furrow, iOS developer |
Apples documentation for Sprite Kit is pretty good, but its not enough. Jonathan and Josh make it easy to understand the concepts behind developing games with Sprite Kit. Throughout the book you will develop two complete games while having fun learning about scenes, sprites, textures, and sounds. Are you building a new game with Sprite Kit? Just buy this book and read it.
Cesare Rocchi, CEO, Studio Magnolia |
As an iOS developer wanting to step into the world of mobile-game development, I really enjoyed reading this book. Its a great introduction to Sprite Kit, explaining the basics and the more advanced stuff very well.
Romain Pouclet, iOS developer, TechSolCom |
Rather than just telling the reader what to do, Jonathan Penn and Joshua Smith walk the programmer through why they are using a given method or set of numbers. Very few people go to this trouble, which is one big reason this book is a must-read.
Janie Clayton-Hasz, iOS developer at Digital World Biology LLC |
After reading the book, game development on iOS seems less wizard-like. I would not be surprised if there were a flood of games released on the market due to how easy the authors made it seem.
This is a fun book! Sprite Kit makes it easier than ever to build games for iOS, and these authors know their stuff and know how to get you up and running with it in no time.
Kevin Munc, mobile developer and founder, Method Up LLC |
This book was so much fun to read and follow along with that by the timeI was done, I had developed a solid grasp of the Sprite Kit APIs plus a fully featured game end-to-end. Well done, Rubber City Wizards!
Zak Nixon, lead software engineer and CEO, Deep Digital LLC |
Preface
Imagine going back in time to visit the people who wrote for the original Atari 2600 game console and showing them games on an iPhone. Jaws would drop. Minds would be blown. Theyd probably check for smoke and mirrors.
Weve come a long way from the video game industrys humble beginnings. Writing games was a challenge back then. It still is today, of course, but the challenges then involved shoving individual pixels around, saving CPU cycles for rudimentary sounds, and interpreting raw player input from analog joysticks. Today, our challenges are often bounded more by our imaginations than by technical constraints.
And thats why we think youve joined us here in this book. You have an unprecedented amount of power in a computer resting in the palm of your hand. You want to write a game, and youd like to do it for iOS. We have good news for you.
Welcome to Sprite Kit! Apples exciting 2D-game development engine sports an excellent API to help bring your 2D game idea from paper to pixels. If youre already an iOS developer, then theres nothing else you need to do. It comes with excellent Xcode support and gives you a template ready to get started. It doesnt get any easier than this.
Sprite Kit provides the scaffolding for you to organize your game code, animate objects on the screen, play sound effects, handle touch events, simulate physical movements and collisions, and more. Any game that functions in two dimensions, such as platformers, puzzles, or overhead action games, will work great with Sprite Kits tools.
This book will help you learn enough to take your own 2D game idea and implement it with Sprite Kits building blocks.
How Do We Get There?
The best way to learn Sprite Kit is to build a game...or two! In this book, well walk through all the steps to build two actual games (that are quite fun, in the authors not-so-humble opinions). We have chosen these games because they provide an opportunity to learn the way of the Sprite Kit APIs step by step.
Lets get to know these games.
Space Run
This will be an infinite runner game, like Canabalt but in space. The goal is just to stay alive as long as possible and rack up points. Its a single-finger game, which makes it a great fit for the casual game market. Check out the sketches in the following figure: