Preface

The App Store is one of the most innovative ways for an indie developer to publish their ideas to the world. You have probably heard the stories of developers striking it rich from an iPhone game they created in their spare time. Money is certainly a good motivator and why many developers are racing to get their ideas published. Do you have the next big game idea? This book is the complete do-it-yourself guide for anyone wanting to make the journey from game idea to App Store.

I’ve never seen such a widespread interest in creating apps and games than right now. Everyone from full-time professionals to children with iPod touches will stop and ask me the same questions: You have games in the App Store?” “How long does it take to create them?” And the one I hear most, “Can someone like me do it?” It seems as though everybody is interested in creating games for this new platform, but most just don’t know where to start.

My entry into app development began August of 2008 when I started working on BubblePop. It’s a game where you have to quickly pop moving bubbles filled with random numbers, and you have to do it in the correct order. I wanted my first game to be simple enough to quickly teach myself the platform, but challenging enough so my friends who helped test it actually found it fun to play.

When I started, I had no knowledge of the Mac, Xcode, or Objective-C. I also only had nights and weekends to work on my game. At the time, there weren’t any relevant books and what could be found online was more about creating apps for jailbroken iPhones and not the official iPhone SDK. Even though I had a lot of things to learn and a full-time job during the day, I was still able to finish my game in a week.

I plowed my way into the App Store through trial and error. Now it was time to wait. My account and game needed to be approved by Apple. It seemed to take forever. It was torture. The day finally came when all the contracts were approved and my game was given the green light. I felt like a kid on Christmas day. It was an amazing feeling seeing my work published on iTunes and available for the world to purchase.

My goal for creating my first game wasn’t to make a million dollars. It was to learn the platform, create a fun game for my iPhone, and hopefully make enough money to pay for the 24-inch iMac that I just bought. As it turns out, I ended up making much more than that—especially when two of my apps, White Noise and Card Counter, hit the big time. In February of 2009, they were both ranked in the Top 20 overall for paid apps. I felt like I won the lottery when the sales report showed I was making over 10 times my current job salary. This was the moment I decided that my fun little hobby should become my full-time job. I have been creating apps and games ever since. I hope you can do the same.

—Todd Moore

Who Should Read This Book

I have been approached by numerous people who have ideas for games but just don’t know where to start. If you have the funds, you could hire a team of developers and artists to create your vision. I’ve found that experienced smartphone developers and graphic artists do not come cheap. As an indie developer, it is important to learn all the skills necessary to do it yourself and hire out only when necessary.

This book is catered to those who have some coding experience but have never developed for the iOS platform. Have you built applications that run on either the PC or Mac platforms? Are you doing server-side web development with ASP.NET, PHP, or Perl and want to try building native apps? Do you already know C or C++ but have no clue about Objective-C? Or do you just want to learn how to build an iPhone game as fast as possible? If you answered “yes” to any of those questions then keep reading. I’m writing this book as the guide I wish I had when I created my first game.

What You Will Learn

I want to teach you how to create a game that uses those aspects of the iPhone hardware that make it unique when compared to other platforms. Most games are typically controlled using a directional pad, analog joysticks, and various buttons. The iPhone and iPad give us a new form of input—Multi-touch. We can track up to 5 individual touches on the iPhone and iPod touch screens and up to 11 individual touches on the iPad. This opens up a whole new genre of games that previously did not exist. This is why you are going to learn right from the start how to handle multiple touches on the screen.

You will quickly build a two-player game that uses multi-touch—and the exciting part is that most of it can be written with about 20 lines of code! Granted, it will look like the 1972 game of Pong, which probably won’t be exciting for you unless you grew up with Atari’s Home Pong console like I did. It is worth noting that the same techniques used back then also apply today in terms of game elements.

Let’s think about that for a second. What does one of the oldest games, Pong, have in common with a 3-D first-person shooter like Call of Duty: Modern Warfare? Graphically, not much, but the game elements are actually the same—you control a player, that player has a position within a defined world, there is a goal to accomplish, and a score to measure your progress. Whether you are racking up points hitting a ball with a paddle or fragging your friends in a 3-D immersive world, the overall game elements are still the same. This is why I will start with a very simple concept and show you how to develop a more modern game moving forward.

You will take the game to the next level with flashy graphics and realistic sound effects. I’ll show you a few tricks of the trade that are usually known only by graphic artists and sound engineers. It is extremely important as an indie developer to learn these skills in order to save time and cut costs. That’s why this book has chapters dedicated toward creating graphics and sounds. I will show you how to make the game look and sound like a real game of air hockey.

As you develop and test the new game you might notice that looks can be deceiving as the game feels nothing like actual air hockey. The puck doesn’t move like it’s on a sheet of ice. The table surface has no friction. Striking the paddle against the puck produces incorrect angles and velocity. You are noticing things about the underlying physics of the game that need to be fixed. I’ll show you how to apply the math you learned in school, and thought you’d never use, to make our air hockey game feel like it’s the real thing.

The final addition to the game will be creating a single-player mode that allows you to play the computer. Computer AI can be the most complicated and important part of any single-player game and this book makes the process as painless as possible. The first step is creating an algorithm that gives the computer perfect, unbeatable play. Games would not be fun if you couldn’t sometimes win, so we’ll introduce a dumbness factor that will make the computer player appear more human and make occasional mistakes. Having a mechanism to scale back how smart the computer player is will in turn give you the ability to have multiple levels of difficultly, ranging from easy to impossible.

Once the game is complete, you’ll learn how to prepare it for the App Store. You will write a marketing description, create compelling screenshots, and submit everything to Apple for approval.

Let the journey begin!

Conventions Used in This Book

The following typographical conventions are used in this book:

Italic

Indicates new terms, URLs, email addresses, filenames, and file extensions.

Constant width

Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.

Constant width bold

Shows commands or other text that should be typed literally by the user.

Constant width italic

Shows text that should be replaced with user-supplied values or by values determined by context.

Note

This box signifies a tip, suggestion, general note, warning, or caution.

Using Code Examples

This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Tap, Move, Shake by Todd Moore (O’Reilly). Copyright 2012 Todd Moore, 978-1-449-30345-7”

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

Safari® Books Online

Note

Safari Books Online is an on-demand digital library that lets you easily search over 7,500 technology and creative reference books and videos to find the answers you need quickly.

With a subscription, you can read any page and watch any video from our library online. Read books on your cell phone and mobile devices. Access new titles before they are available for print, and get exclusive access to manuscripts in development and post feedback for the authors. Copy and paste code samples, organize your favorites, download chapters, bookmark key sections, create notes, print out pages, and benefit from tons of other time-saving features.

O’Reilly Media has uploaded this book to the Safari Books Online service. To have full digital access to this book and others on similar topics from O’Reilly and other publishers, sign up for free at http://my.safaribooksonline.com.

How to Contact Us

Please address comments and questions concerning this book to the publisher:

O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at:

To comment or ask technical questions about this book, send email to:

For more information about our books, courses, conferences, and news, see our website at http://www.oreilly.com.

Find us on Facebook: http://facebook.com/oreilly

Follow us on Twitter: http://twitter.com/oreillymedia

Watch us on YouTube: http://www.youtube.com/oreillymedia

Get Tap, Move, Shake now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.