Beginning iPhone Game Development

Mark SzymczykAug 26, 2010

Beginning iPhone Games Development

The title of the book ‘Beginning iPhone Games Development’ by Peter Bakhirev, PJ Cabrera, Ian Marsh, Scott Penberthy, Ben Britten Smith, and Eric Wing tells you what the book covers: iPhone game development. Four areas make up the core of the book.

  • Quartz and Core Animation
  • OpenGL ES
  • Audio
  • Networking

Several of the chapters use a tutorial approach that walks the reader through the creation of a game. In the course of the walkthrough, other game development topics like timing, game loops and collision detection are covered. But you’re not going to see entire chapters devoted to anything besides graphics, audio, and networking.

Quartz and Core Animation

Three chapters make up the Quartz and Core Animation section. The first chapter goes through the creation of a Breakout clone. In the course of creating the game, the reader learns the basics of using Interface Builder, reading user input, creating a timer, moving the ball, and simple collision detection. The chapter also shows you how to read the accelerometer and handle touch events. In the course of one chapter you end up with a working level of Breakout, which is impressive.

The second chapter covers Quartz. Over the course of the chapter the author creates an Asteroids clone. Some of the things you’ll learn by creating the Asteroids clone include sprite animation, changing the screen orientation from portrait to landscape, and drawing text on the screen. The chapter also explains the Model-View-Controller (MVC) design pattern and shows how the MVC pattern fits into a game loop.

The third chapter covers Core Animation. The chapter does a good job of introducing Core Animation, but I found the chapter to be unnecessary. Core Animation doesn’t fit well into the games the book creates so most of the Core Animation code involves a sample program that animates a chicken. The book says Core Animation is used for things like intro screens and cutscenes. An example of using Core Animation for an intro screen or cutscene would have made the Core Animation material more useful to iPhone game developers.

The chapters in the Quartz and Core Animation section are slower-paced and do more hand holding than the rest of the chapters. People new to game development will get the most out of these chapters.


The OpenGL ES section consists of three chapters. The first chapter introduces OpenGL ES and sets things up for the next two chapters. Some of the topics the chapter covers include matrices, the rendering loop, Apple’s EAGLView, setting up a viewport, and projection.

The second chapter takes the OpenGL ES material in the first chapter and uses it to create an Asteroids clone with vector graphics. This version of the game is built upon in later chapters, especially in the audio section of the book. Some of the topics covered in the chapter include creating buttons in OpenGL ES, converting OpenGL coordinates to screen coordinates, working with vertices, firing missiles, and collision detection. The collision detection material is especially good. After reading the chapter you’ll know how to implement a fast and accurate collision detection system.

The last chapter covers texture mapping, using 3D models with lighting, and particle systems. Some of the texture mapping topics in the chapter include reading image data from a file into OpenGL ES, binding textures, texture coordinates, drawing textures, and texture atlases. A texture atlas combines multiple images into one texture, which helps your game’s performance by minimizing the number of times you change textures.

The 3D material covers normals, combining textures and 3D models, lighting, shading, and culling vertices that are blocked by other objects. The 3D topics are basic because the book is geared towards beginners. You’re not going to be writing a first-person shooter after reading this chapter.


The audio section is the largest section of the book at almost 225 pages. The material in this section is more advanced than you would expect from a book geared towards beginners. After reading the audio section you’ll know pretty much everything you need to have great audio in your iPhone game.

The audio chapters cover Core Audio and OpenAL. Because Core Audio and OpenAL are also available on Mac OS X, this section can help Mac game developers as well as iPhone developers.

Four chapters comprise the audio section of the book. The first chapter covers Core Audio. The chapter begins by introducing the frameworks that make up Core Audio. After introducing the frameworks, the chapter moves on to a discussion of the file formats and codecs Core Audio supports. The chapter ends by showing how to play sounds with Core Audio.

The second chapter introduces OpenAL. The introduction to OpenAL involves two main topics. The first topic is setting up OpenAL and playing sounds. The second topic is creating a resource manager to deal with OpenAL’s limits on the maximum number of generated sources and simultaneously playing sources. An OpenAL source represents a point that emits sound. If you have lots of entities on the screen in your game and each entity emits sound, you can easily reach OpenAL’s limits.

After reading the second chapter, you’ll know how to play sounds with OpenAL. But OpenAL is a 3D audio API. If you’re not going to use OpenAL’s 3D capabilities, you might as well use Core Audio. This is where the third chapter comes in. The third chapter covers 3D audio. In the chapter you learn how to apply realistic 3D audio effects with OpenAL.

The fourth chapter’s main topic is streaming large files using both Core Audio and OpenAL. The chapter also covers playing music from the player’s music library so someone could use a song on their iPhone as the background music in your game. The final audio topic is recording audio from the microphone on the player’s device. Many games don’t need to record audio, but audio recording can be used for things like taunting opponents.


There are four chapters in the networking section. The first chapter provides a high-level overview of networking and the networking technologies the iPhone uses.

The second chapter walks the reader through the networking involved in Pong. After reading the chapter, you’ll know how to send and receive messages, handle disconnects, and use GameKit to find an opponent.

The third chapter covers multi-player games with Bonjour over a local WiFi network. The chapter goes through the networking involved with the game TwentyFour. For those of you unfamiliar with the game TwentyFour, which included me before I read the book, the players are given four random numbers ranging from 1 to 9. The object of the game is to use addition, subtraction, multiplication, and division to make the four numbers add up to 24. If you were given the numbers 2, 4, 5, and 8, you could use the following expression to get 24:

((8 * 5) / 2) + 4

The TwentyFour game uses the client/server architecture. In the course of the chapter, the author explains the client’s and server’s responsibilities in the game. After explaining the responsibilities, he shows the implementation of the client and the server with lots of code listings.

The fourth chapter covers connecting to the Internet so you can do things like play against a friend who lives 1000 miles away and share high scores online. The material provides a high-level overview of what you have to do to add Internet support to your games. There’s no code in the chapter. If you want to handle networking over the Internet instead of over Bluetooth or Wi-fi, you’ll have to look elsewhere.

What Isn’t Covered

No game programming book can cover everything involved in game development. The following topics are not covered in the book:

  • iPad development.
  • OpenGL ES 2.0 so there’s no coverage of shaders.
  • Compressed textures, which is a little surprising because compressed textures are easier to code than uncompressed textures.
  • Artificial intelligence.
  • Physics, outside of the collision detection material.

Source Code

Source code for the book is available to download from the publisher’s website. There are four games in the source code download: a Breakout clone, an Asteroids clone, Pong, and TwentyFour. For topics that don’t fit into the games the book creates, small demonstration applications are included in the source code.

The source code comes with Xcode projects (40 of them) and uses the iPhone 3 SDK. I used Xcode 3.2.3 and the iPhone 4 SDK to build the projects. For those of you using the iPhone 4 SDK, the projects will tell you the Base SDK is missing because installing the iPhone 4 SDK erases older installed versions of the iPhone SDK. Changing the Base SDK build setting allowed me to build for the Simulator with no errors. Some of the projects had the author’s code signing identity in the project or were set to not code sign, which caused an error when I tried to build for the device. Setting the code signing identity to my identity solved the problem.

Most of the programs ran with no problems. Two versions of the OpenGL Asteroids game had a bug where the game didn’t recognize touch events, which made the game unplayable. On the book’s forum I discovered the fix, which involved adding a second condition to an if statement. After making the fix, the games worked well.

I did not test whether the code listings in the text matched the downloaded source code. There are lots of code listings in the book, and to check them all for consistency would have delayed this review by months. The downloaded source code mostly worked well so I recommend using it over what’s printed in the text.

Who Would Benefit From This Book?

Beginning iPhone Games Development’s material works best for people with some game development experience who are new to iPhone game development. The book covers the technologies a developer needs to write iPhone games. Seasoned game developers who have some Cocoa or Cocoa Touch experience should be able to make the transition to iPhone development after reading this book. Someone coming to iPhone game development from Windows or Linux may need to learn some Cocoa and Objective-C to get through the book.

For someone new to game development who wants to write iPhone games, there is a lot of good material in this book. But you may need some supplemental material, either a second game development book or online tutorials, to get the most out of the book. The book focuses on iPhone-specific topics so someone who doesn’t know game programming terminology may have a difficult time getting through some of the material.

About the Reviewer

Mark Szymczyk is a long time member and contributing writer to iDevGames. Thanks to being discovered for writing a series of game programming articles for iDevGames, Premier Press published his first book Mac Game Programming. Mark has since gone on to write Xcode Tools Sensei (with an upcoming second edition covering Xcode 4), and a series of game and Mac developer related articles available on his website, Me and Mark Publishing.

uDevGames 2011

Convergence — Best Gameplay
Kung Fu Killforce — Best Overall Game, Best Audio, Best Presentation
Flying Sweeden — Best Graphics, Most Original
Time Goat — Best Story