iOS Game Programming Overview
Jan 13, 2013—
Who this Article is For
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 creating iOS games.
- Recommended Reading: Game Programming for Beginners
The iOS SDK
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 an understanding 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 the iPhone and iPad. To run the game on a physical device, however, you will need to join the iOS Developer Program for just $99 per year. Without joining the program, you’ll be limited to running your game inside of the iOS simulator on a Mac.
Tools and Languages
Once you have the SDK, you need to be familiar with the different frameworks and tools available to you. The primary tool you’ll be using is the Xcode IDE, which is the combined code editor, debugger, interface builder, and tool for uploading applications into the App Store. Other tools included in the SDK include Instruments (for finding memory leaks and doing in-depth performance evaluation of your code), and the iOS Simulator. There is a wealth of information on how to use Xcode and these tools on Apple’s website in the Developer Library. There are also many tutorials and books available.
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. Although you can write your game in many other languages and use abstracted game creation tools where you use graphical editors or scripting to create your app, fundamentally the connection between your game and iOS itself is done through a number of Objective-C APIs or “frameworks” which serve different purposes. Programming in Objective-C using the Apple-provided frameworks is commonly referred to as “Cocoa programming”, and also applies to development on the Mac. iOS developers often refer to the collection of iOS frameworks as “Cocoa Touch” to make a distinction.
Some of the primary frameworks involved in iOS development are Foundation, UIKit, Core Graphics, Core Animation, Core Motion, and OpenGL. UIKit is a collection of Obj-C classes which implement things such as buttons, sliders, popups, text fields, image views, etc. Foundation contains the Obj-C classes NSString, NSArray, NSDictionary, and many others; basically it contains the core data types and utilities used in programming.
The primary graphics APIs in iOS are Core Graphics, Core Animation, and OpenGL ES. Core Graphics functions draw 2D graphics using the CPU, while OpenGL ES, uses the GPU to render. Although OpenGL is designed for 3d graphics, 2d graphics are just as easy to use in it, and because OpenGL is efficient and “hardware-accelerated” by using the GPU, this is what the vast majority of games use to do their drawing. Core Animation isn’t really a graphics API in the same sense that CG and OpenGL are, but instead is more of an API for handling the layout and movement of existing graphical content. For games, you have all three options to work with, but typicall you will use either Core Animation or OpenGL.
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, StoreKit for in-app purchases, the Social framework for Facebook and Twitter integration, and many others.
Making a Game from Scratch
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.
Although creating a game from scratch is more time consuming, you learn far more about game development and programming as a whole, and the challenge is very rewarding.
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. There 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 that you could use with iOS include very high end solution such as Unity and Unreal Dev Kit. See The Big List of Mac and iOS Game Engines for a list of game engines available.
The App Store
The only way to distribute your game so that other people can purchase and play it, is to submit it to Apple’s App Store. The process of submitting to the App Store first involves
- You must be an iOS Developer Program member. ($99 per year)
- You must create a game that adheres to the App Review Guidelines.
The review guidelines are a comprehensive list of rules your app/game must strictly adhere to in order to be included in the App Store. These guidelines are far reaching and include rules governing the quality, behavior, and appearance of your app. While not overly restrictive by any means, you must be sure to not break any rule, lest your app be reject from the App Store. The submission process can also take a lengthy amount of time before your app is approved, but once your app is accepted, you have millions of potential customers awaiting your game!