If you’re reading this Preface, you might be trying to decide whether this book is right for you. So, we’ll explain what we intend to cover and who we expect will get the most out of reading the book. But we’ll start with why you should even listen to us.
We’re two programmers who have been buddies in the Los Angeles area for a long time and have been making mobile games since 2003. Between the two of us we have developed and ported close to a hundred titles for cell phones, including Ninja Gaiden, Castlevania: Order of Shadows, Dance Dance Revolution: Mobius, and Contra 4, among many, many others. Paul currently works for Konami, and occasionally gives lectures about game programming at USC. Joe works at EA and recently published a game for the iPhone. Paul wrote most of the theory, while Joe cooked up some great example projects.
We expect there is—scratch that—we know there is a lot of interest in the iPhone as a new game platform. The high-end hardware promises plenty of power and memory for graphics and content, while the unique touch screen and gyroscope interface pose an interesting challenge that encourages innovative game designs. Add to that the open market of the iTunes App Store, which promises easy entry for independent developers as well as accurate revenue tracking for serious publishers, and it’s no surprise that the iPhone is making a huge splash in the mobile space.
Our goal was to write a book that can put iPhone game development in the reach of any programmer out there, in a format that suits both beginning and advanced game programmers.
This book is not a course on Objective-C, though it will contain a primer. This book is not an exhaustive study of the iPhone SDK, as we will use only the functionality needed to make our games. This book is not a five-year course on game programming technology. However, this book is the source for all you need to know not only to build the example games we have provided but also to build your own.
By the end of the book, you will have learned all of the core concepts of creating a game engine, and how to apply it to the iPhone. You will learn enough Objective-C to utilize the iPhone SDK to make a 2D game. You will have been introduced to OpenGL ES on the iPhone for making 3D games. And finally, you will be familiar with the certification process so that making the last plunge into the App Store is much less scary.
To get the most out of this book, you will need to have some programming knowledge. The iPhone uses Objective-C, but most people are more familiar with C/C++ or Java, so the Objective-C primer in Chapter 1 will help familiarize you with the basics.
You will also need a Mac. The iPhone Software Development Kit (SDK) is available only for OS X, so a trip to the Apple store may be in your future if you are serious about developing for the iPhone. Fortunately, the base model Mac Mini has plenty of power to develop for the iPhone, and you can use your existing monitor and keyboard setup. Meanwhile, once you have a Mac, the Xcode Integrated Development Environment (IDE) is free. But we’re getting ahead of ourselves.
The third requirement is not 100% necessary, but strongly recommended: an iPhone or iPod Touch. Although we use the term iPhone throughout the book, games made for the iPhone will also work on iPod Touch. Some people will undoubtedly try to create an iPhone game using only the iPhone Simulator. It may be possible to do this, and even get it placed into the App Store, but we strongly recommend that you develop and test on the device itself. After all, what good is a game you can’t play yourself?
Beyond those three requirements, everything else you need you can either download or learn. We are working on useful classes and examples at https://sourceforge.net/projects/iphonegamebook/, where you will also find the source code for all examples.
As we mentioned earlier, we expect you to have some basic programming knowledge. That aside, all kinds of programmers are interested in the iPhone. Developers of all levels are going to be reading up to try their skill.
You might not have any game programming experience and will need some basic theory on game engines and user-interface design. Or perhaps you have plenty of experience making video games on other platforms and just need to become familiar with the iPhone SDK and build process, along with some touch-screen concepts. You may also be interested in advanced topics, such as how to write portable code for cross-platform games and what middleware solutions currently exist. Either way, this book has got you covered.
Organization of This Book
Chapter 1, Introduction to the iPhone, gets you set up to build interfaces and write code in Objective-C, including logistics such as setting up a developer account with Apple.
Chapter 2, Game Engine Anatomy, introduces the elements of game logic and good design that will let you write a maintainable and enjoyable game application.
Chapter 3, The Framework, shows the code that will wrap your particular game implementation as well as critical classes we wrote to supplement the features provided by the Apple SDK.
Chapter 4, 2D Game Engine, creates a complete four-level game based on the framework in Chapter 3. We start with 2D because both the game tasks and the coding complexity are much easier in 2D than in 3D. Basic movement, visual and audio effects, movement through game levels, and other elements of game programming are covered.
Chapter 5, 3D Games, explains the more sophisticated tasks required to write a 3D game. Although the chapter uses the OpenGL library, its goal is not to explain 3D basics or OpenGL, but to give you the unique skills required to use them in game programming.
Chapter 6, Considerations for Game Design, wraps up the book with some large-scale considerations for advanced developers, and pointers to more resources, including useful libraries and middleware.
Appendix A, points to useful sources of information, libraries, and products.
Conventions Used in This Book
The following typographical conventions are used in this book:
Indicates new terms, URLs, filenames, and file extensions
Indicates variables, method names, and other code elements, as well as the contents of files
Constant width bold
Highlights new code in an example
Constant width italic
Shows text that should be replaced with user-supplied values
This icon signifies a tip, suggestion, or general note.
This icon indicates a 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: “iPhone Game Development by Paul Zirkle and Joe Hogue. Copyright 2010 Paul Zirkle and Joe Hogue, 978-0-596-15985-6.”
If you feel your use of code examples falls outside fair use or the permission given here, feel free to contact us at email@example.com.
We’d Like to Hear from You
Every example in this book has been tested, but occasionally you may encounter problems. Mistakes and oversights can occur and we will gratefully receive details of any that you find, as well as any suggestions you would like to make for future editions. You can contact the authors and editors at:
|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)|
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 the following, quoting the book’s ISBN number (9780596159856):
For more information about our books, conferences, Resource Centers, and the O’Reilly Network, see our website at:
Safari® Books Online
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.
Thanks to Andy Oram, Marlowe Shaeffer, Isabel Kunkle, and the rest of the crew at O’Reilly. Special thanks to Erin Reynolds, for game art. Thanks to Brad O’Hearne, Jonathan Hohle, and Trina Gregory for technical reviews of this book. And thanks to all of the readers who left comments on Rough Cuts.
Paul would also like to thank his family, Amanda Joy and William “Nizor” Eiten.