iOS Game Programming Overview

iDevGames — Feb 16, 2011

The iOS SDK

iOS games are an exciting, large, and rapidly growing market. Every day dozens of games are released for Apple’s iOS-based iPhone, iPod, and iPad. Given the possibility of having millions of customers with your game literally at their fingertips, it’s no surprise game developers are excited about created iOS games.

So as a new developer, where do you need to start to make your own iOS games? First, read the general introduction to game programming here on iDevGames to get and understand of what game development involves. Then, for iOS game development, you first need to get your hands on a copy of Apple’s iOS SDK from http://developer.apple.com. The SDK contains everything you need to build any kind of app or game for iOS. To run the game on a physical device, however, you will need to join the iOS Developer Program for just $99 per year.

Once you have the SDK, you need to be familiar with the different frameworks and tools available to you. The primary tools you’ll be using are the Xcode IDE along with Interface Builder (which is built into Xcode 4+). The Apple documentation talks all about how to use Xcode and Interface Builder, so we won’t go into any details on that. Suffice to say that, you use Xcode to write your code, and Interface Builder to layout and connect pieces of the interface of your app (if needed).

At the code level, the primary language used in iOS development is Objective-C. Obj-C is a superset of C, meaning any valid C code is valid Obj-C code as well. The primary frameworks involved in iOS development are Foundation, UIKit, Core Graphics, Core Animation, and OpenGL. UIKit is a collection of Obj-C classes which implement things such as buttons, sliders, popups, text fields, image views, etc. UIKit is akin to “AppKit” in Mac OS X, although unlike on the Mac, every view in UIKit is also a Core Animation layer. Foundation contains the Obj-C classes NSString, NSArray, NSDictionary, and many others; basically it contains the core data types and utilities used in Cocoa programming.

All drawing on iOS is done either using Core Graphics, or OpenGL ES. Core Graphics functions draw 2D graphics into a bitmap context. OpenGL ES is the mobile version of the industry standard OpenGL 3d graphics library. Although OpenGL is designed for 3d graphics, 2d graphics are just as easy to use in it. This is what the vast majority of games use to do their drawing, because OpenGL is efficient and hardware-accelerated, meaning you’ll get the best performance out of.

There are also many other frameworks in the iOS SDK. Among them, you have Core Audio and OpenAL for audio, MediaPlayer for movies, GameKit for peer-to-peer networking, chat, leaderboards, etc, iAd for placing ads into your game to earn revenue, and many others.

Making a Game

To create a game with the iOS SDK “from scratch”, typically you would use a combination of C and Objective-C code with OpenGL ES for graphics, OpenAL for audio sound effects, Core Audio for streaming music, GameKit for multiplayer/social connectivity, and perhaps a third party physics library such as Chipmunk Physics for handling collision detection and response and other physics behaviors in your game.

As an iOS developer, you also have several choices for third-party game development libraries. These libraries are specifically designed to make creating games easier by providing you with functionality that you’d normally need to create yourself.

iOS Game Engines

Perhaps the most widely-used of game engine for iOS is cocos2d for iPhone. cocos2d has a long feature list including OpenGL ES-based graphics, integration with the physics libraries Box2d and Chipmunk, a particle system, scene management, effects *such as waves, ripples, etc), sound support, tile maps, and more. It also is adding some support for 3D graphics. cocos2d is also now available for Mac OS X, so you can deploy the same game made in cocos2d on the iPhone, iPod, iPad, and Mac. One other benefit of cocos2d is that there are already a few books written specifically using it to create games for iOS.

Other game engines available for iOS (in no particular order) include: