Home > Store

Learning iOS Game Programming: A Hands-On Guide to Building Your First iPhone Game

Register your product to gain access to bonus material or receive a coupon.

Learning iOS Game Programming: A Hands-On Guide to Building Your First iPhone Game


  • Sorry, this book is no longer in print.
Not for Sale


  • Copyright 2011
  • Edition: 1st
  • Book
  • ISBN-10: 0-321-69942-4
  • ISBN-13: 978-0-321-69942-8

Get Started Fast with iOS Game Programming

Since the launch of the App Store, games have been the hottest category of apps for the iPhone, iPod touch, and iPad. That means your best chance of tapping into the iPhone/iPad “Gold Rush” is to put out a killer game that everyone wants to play (and talk about). While many people think games are hard to build, they can actually be quite easy, and Learning iOS Game Programming is your perfect beginner’s guide. Michael Daley walks you through every step as you build a killer 2D game for the iPhone.

In Learning iOS Game Programming, you’ll learn how to build a 2D tile map game, Sir Lamorak’s Quest: The Spell of Release (which is free in the App Store). You can download and play the game you’re going to build while you learn about the code and everything behind the scenes. Daley identifies the key characteristics of a successful iPhone game and introduces the technologies, terminology, and tools you will use. Then, he carefully guides you through the whole development process: from planning storylines and game play all the way through testing and tuning.

Download the free version of Sir Lamorak’s Quest from the App Store today, while you learn how to build the game in this book.


Coverage includes 

  • Planning high-level game design, components, and difficulty levels
  • Using game loops to make sure the right events happen at the right time
  • Rendering images, creating sprite sheets, and building basic animations
  • Using tile maps to build large game worlds from small reusable images
  • Creating fire, explosions, smoke, sparks, and other organic effects
  • Delivering great sound via OpenAL and the iPhone’s media player
  • Providing game control via iPhone’s touch and accelerometer features
  • Crafting an effective, intuitive game interface
  • Building game objects and entities and making them work properly
  • Detecting collisions and ensuring the right response to them
  • Polishing, testing, debugging, and performance-tuning your game 

Learning iOS Game Programming focuses on the features, concepts, and techniques you’ll use most often—and helps you master them in a real-world context. This book is 100% useful and 100% practical; there’s never been an iPhone game development book like it!

Praise for Learning iOS Game Programming

“An excellent introduction into the world of game development explaining every aspect of game design and implementation for the iPad, iPhone, and iPod touch devices. A great way for anyone interested in writing games to get started.”

–Tom Bradley, Software Architect, Designer of TBXML

“A great developer and a great game.That’s everything you can find in this book to learn how to write an awesome game for iPhone.Maybe you’re the next AppStore hit!”

–Sebastien Cardoso

“With Learning iOS Game Programming, you’ll be writing your own games in no time. The code included is well explained and will save you hours of looking up obscure stuff in the documentation and online forums.”

–Pablo Gomez Basanta, Founder, Shifting Mind

“I always thought that to teach others one has to be an expert and a person with an established reputation in the field. Michael Daley proved me wrong. He is teaching others while studying himself. Michael’s passion in teaching and studying, ease of solutions to problems, and a complete game as a resulting project makes this book one of the best I have ever read.”

–Eugene Snyetilov

“If you’re interested in 2D game programming with the iOS using OpenGL and OpenAL directly, this book walks you through creating a complete and fun game without getting bogged down in technical details.”

–Scott D.Yelich

“Michael Daley brings clarity to the haze of iPhone application development. Concrete examples, thorough explanation, and timesaving tips make this book a must have for the up and coming iPhone game developer.”

–Brandon Middleton, Creator of Tic Tac Toe Ten

“This is the A-Z guide to iOS game development; Michael’s book takes you from the basics and terminology to using the techniques in practice on a fully working game. Before you know it, you will find yourself writing your own game, fueled by a firm grasp of the principles and techniques learned within. I could not ask for a better reference in developing our own games.”

–Rod Strougo, Founder Prop Group



Download the source code

Sample Content

Online Sample Chapter

Learning iOS Game Programming: Sprite Sheets

Sample Pages

Download the sample pages (includes Chapter 6 and Index)

Table of Contents

Preface     xxi

1   Game Design     1

The Game That Started It All (For Me)     3

So, What’s the Big Idea?     4

  A Game That Fits with the iPhone     4

  The Storyline     5

  What’s in a Name?     5

  The Game’s Objective     6

Game Play Components     7

  Time     7

  Lives     7

  Health     8

  Objects     8

  Doors     9

  Weapons     10

  Entities     10

  Player     11

Summary     11

2   The Three Ts: Terminology, Technology, and Tools     13

Terminology     14

  Sprite     14

  Sprite Sheet     16

  Animation     18

  Bitmap Fonts     19

  Tile Maps     20

  Particle System     21

Collision Detection     22

  Artificial Intelligence (AI)     23

  Game Loop     24

Technology     26

  Objective-C     26

  Cocoa Touch     27

  OpenGL ES     27

  OpenAL     30

Tools     31

  The iPhone SDK     32

Summary     38

3   The Journey Begins     39

Creating the Project in Xcode     39

Running the Project     42

Under the Hood     43

Application Delegate     43

  Examining the Header File     44

  Examining the Implementation File     46

EAGLView     49

  EAGLView.h     49

  EAGLView.m     50

ES1Renderer     58

  Examining ES1Renderer.h     58

  Examining ES1Renderer.m     59

  Creating the Framebuffer and Renderbuffer     60

  Defining the Color Values     66

  Positioning     67

How OpenGL Works     68

  Applying Transformations on the Model     69

  Rendering to the Screen     70

Summary     72

4   The Game Loop     73

Timing Is Everything     73

Collision Detection     74

The Game Loop     75

  Frame-Based     75

  Time-Based, Fixed Interval     77

Getting Started     78

  Inside the EAGLView Class     79

  Inside the EAGLView.m File     79

  ES1Renderer Class     82

  Configuring the View Port     85

Game Scenes and the Game Controller     86

  Creating the Game Controller     87

  The GameController Class     87

  Creating the Singleton     89

  Inside GameController.m     89

  AbstractScene Class     92

  GameScene Class     93

Summary     95

Exercises     95

5   Image Rendering     97

Introduction to Rendering     97

Rendering a Quad     98

Texture Mapping     101

  Texture Coordinates      101

Interleaved Vertex Arrays     104

Structures     106

Image Rendering Classes     107

  Texture2D Class     108

  TextureManager Class     116

  ImageRenderManager Class     119

The Image Class     126

I  nitialization     126

  Retrieving a Sub-Image     129

  Duplicate an Image     130

  Rendering an Image     130

  Getters and Setters     134

Summary     134

Exercise     135

6   Sprite Sheets     137

Introduction to Sprite Sheets     137

  Simple Sprite Sheet     138

  Complex Sprite Sheets     139

Using Zwoptex     141

The SpriteSheet Class     142

  Initialization     143

  Retrieving Sprites     146

PackedSpriteSheet Class     147

  Initialization     147

  Parsing the Control File     148

  Retrieving a Sprite     149

Summary     150

Exercise     151

7   Animation     153

Animation Chapter Project     153

Introduction to Animation     154

  Frames     154

  State     w155

  Type     155

  Direction     155

  Bounce Frame     155

Animation Class     156

  Initialization     156

  Adding Frames     157

  Animation Updates     158

  Animation Rendering     160

  Finishing Things Off     161

Summary     163

Exercise     163

8   Bitmap Fonts     165

Bitmap Font Project     165

Introduction to Bitmap Fonts     166

Creating the Bitmap Font Sprite Sheet     167

The BitmapFont Class     170

  Header File     170

What’s with the C?     171

  Initializer     171

  Parsing the Control File     172

Rendering Text     176

  Rendering Justified Text     178

  Text Width and Height     180

  Deallocation     181

Summary    181

Exercise     182

9   Tile Maps     183

Getting Started with the Tile Map Project     183

Introduction to Tile Maps     184

Tile Map Editor     186

  Tile Palette     188

  Layers     188

Creating a Tile Map     189

  Create a New Tile Set     190

  Creating Map Layers     191

  Creating Object Layers     191

  Drawing the Map     192

  Placing Objects    192

Understanding the Tiled Configuration File     193

  Map Element     193

  Tileset Element     193

  Layer Element     194

  Object Group Element     195

Tile Map Classes     196

  Layer Class     196

  TileSet Class     202

  TiledMap Class     204

  Initialization     205

  Parsing a Map File    207

  Creating the Layer Images     216

  Rendering a Layer     218

  Getting Tile Informaiton     220

Summary     220

Exercise     221

10   The Particle Emitter     223

Particle Emitter Project     224

  Introduction to Particle Systems     225

  Particle System Parameters     226

Life Cycle of a Particle     227

  A Particle Is Born     227

  A Particle Lives     228

  A Particle Dies     229

  A Particle Is Reborn     229

Particle Emitter Configuration     230

Particle Emitter Classes     231

  TBXMLParticleAdditions Class     231

  ParticleEmitter Class     233

Have a Play     247

Summary     248

11 Sound     249

Sound Project     249

Introduction to Sound on the iPhone     250

  Audio Sessions     250

  Playing Music     252

  Playing Sound Effects     252

  Creating Sound Effects     254

  Stereo Versus Mono     256

Sound Manager Classes     256

  SoundManager Class     257

Sound Effect Management     273

  Loading Sound Effects     274

  Playing Sound Effects     276

  Stopping Sound Effects     279

  Setting Sound Effect and Listener Position     281

Handling Sound Interruptions     281

Summary     284

12   User Input     285

User Input Project     285

Introduction to User Input     287

  Touch Events     287

Processing Touch Events    289

  The touchesBegan Phase     290

  The touchesMoved Phase     292

  The touchesEnded Phase     294

Processing Taps     294

Accelerometer Events     296

Summary     298

13   The Game Interface     299

Game Interface Project     299

OpenGL ES Interface     300

  Rendering the Interface     301

  Defining Button Bounds     304

  Handling Touches     304

  Handling Transitions     308

  OpenGL ES Orientation     308

UIKit Interfaces     312

  Creating the Interface     312

  Wiring Up the Interface     315

  UIKit Orientation     318

  Showing and Hiding a UIKit Interface     320

Summary     323

14   Game Objects and Entities     325

Game Objects and Entities Project     325

Game Objects     326

  AbstractObject Class     327

  EnergyObject Class     329

Game Entities     338

  AbstractEntity Class     339

  Artificial Intelligence     341

  Player Entity Class     343

Saving a Game Object or Entity     352

Summary     355

15   Collision Detection     357

Introduction to Collision Detection     357

  Collision Pruning     358

Frame-Based Versus Time-Based     359

Axis-Aligned Bounding Boxes     360

Detecting Collisions     361

Collision Map     362

Entity-to-Map Collision Detection     365

Entity-to-Entity Collision Detection     367

Summary     368

16   Putting It All Together     369

The “Camera”     369

Saving the Game State and Settings     371

  Saving Game State     371

  Loading Game State     373

  Saving Game Settings     375

  Loading Game Settings     376

Saving High Scores     377

  Adding a Score     379

  Saving High Scores     380

  Loading High Scores     381

Performance and Tuning     382

  Using Instruments     383

  Leaks Instrument     384

  Using the OpenGL ES Instrument     387

  Compiling for Thumb     389

Beta Testing     390

  Multiple Device Types     391

  Feedback     392

Summary     392

Index     395


Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020