Welcome to my game programming tutorial on how to create a beginners action game for the iOS. This is a step by step tutorial for creating an iPhone action game. The principles taught also apply to the iPad.
You can see the result of a game running the code in the video below:
The graphics are a bit different with the tutorial (as some of those in the video are being used in an actual project) but that is the result of running the actual code within the tutorial.
Specificially the tutorial features:
- Loading/Placing Images
- Touch Events
- Sound Effects
- Background Music
- Resetting The Game
Pre-requisites For This Game Programming Tutorial
Now before we start there are a few pre-requisites. You should have a basic understanding of Objective-C and will need a Mac with the iPhone SDK installed. The game was created using iPhone SDK 4.0, and the Sparrow Framework. Also note that I created this to be as easy to follow as possible so I used a minimum number of classes/methods to make it as easy as possible for a beginner to follow – I’ve even exclusively used autorelease objects so you don’t need to worry about memory management (one of the facets of Objective-C many beginners have trouble with).
Why Am I Using The Sparrow Framework In This Game Programming Tutorial?
In case you’re wondering why I chose to go the route of using the Sparrow Framework it’s because I believe it is the easiest iPhone game development framework available for free for a beginner to start with, and it has already been used in a number of games in the app store.
Please share this tutorial by tweeting it or sharing using one of the buttons at the bottom.
You can navigate through the tutorial by using the page numbers at the bottom of each page.
If you’d like to jump right in you can download a project with all the resources loaded in here.
Getting The Code
You can download the code using the download links at the end of each page, or you can use the Github project found here:
Otherwise if you’d like to go the route of installing Sparrow, and setting everything up you can visit the Sparrow Framework getting started page here which explains the process of setting up an Xcode project that utilizes the Sparrow Framework. You can get just the game assets (graphics/sound) here.
The tutorial is definitely not perfect, and there are probably some spelling/grammar mistakes, but it is the most extensive single tutorial I’ve seen around and might never be released if I tried to perfect it 🙂
The first thing we’re going to do is start the game scene by displaying in a background image, adding the score and level text, and playing some music. To navigate through this game programming tutorial use the page numbers at bottom, now go to page 2 by clicking that number at the bottom of this article to go to that page.
The excellent and free Cocos2D iPhone game engine has been updated with a plethora of new features.
The highlights include:
- a new sound engine
- touch dispatcher
- faster actions
- an improved particle system
If you haven’t tried Cocos and are looking to develop a 2d game on the iPhone quickly without having to purchase a commercial engine you should check out Cocos2D here.
[via cocos2d for iPhone]
Here’s my updated list of OpenGL ES resources, this list includes tutorials, engines, blogs, and books. I have updated it to include a couple of OpenGL ES 2.0 resources, and many other OpenGL ES 1.x resources that others have shared with me.
I have created a new version of this list at: 18 OpenGL ES Resources That You Must Know!
If you don’t have a basic understanding of 2D and 3D math for computer graphics your head will probably explode once you try learning OpenGL. To prevent that from happening you should at least understand the terminology, and the reasons why this math is needed. No need to grind through math problems like in college.. that’s what computers are for.
1. The Black Art of 3D Game Programming Chapter 10 This is a great introduction to graphics math, and pretty much crams 3 college courses I took into this chapter. The whole book can be found here for free. It is an old book, but the math still holds true.
2. Vector & Matrix Math Tutorial If you feel that everything in the resource above is flying above your head then you probably will want to take a look at this. I normally wouldn’t reccomend a resource that brags about being "book sized", but it is very good.
iPhone Specific Resources
3. iPhone OpenGL ES Tutorial Series I don’t know if Maurice SImon is the smartest person alive, but this is the smartest set of OpenGL ES tutorials I’ve seen. A terrific resource.
5. SIO2 Engine this is an excellent Open Source 3D OpenGL ES engine, look at the code, understand, and maybe even use the engine rather than write your own from the ground up (nothing wrong with that).
6. Oolong Engine An Open source 3D OpenGL ES Game Engine for Iphone, MIT licensed. Written by Wolfgang Engel former Rockstar Games programmer, and author of some intense DirectX books. Great to see the libraries in here for handling memory, loading 3d models, and performing math.
7. Cocos2D Iphone This is an excellent Open Source 2D OpenGL ES Game Framework for iPhone you can learn alot from going in and looking around the code. As far as Open Source frameworks go this extremely easy to use, well documented, and has an active community.
8. SDL for iPhone (SDL Version 1.3) The SDL library has been a popular open source library for probably over a decade, and has been used in many games. This is the iPhone port, and a great resource.
Non iPhone Resources
If you use these resources you’ll need to put in some time to get things running on the iPhone, but they are still excellent.
10. Nehe Tutorials Converted To OpenGL ES Michael Gorchak creator of the GluES library has put together this collection of tutorials converted from their original Nehe form. In case you haven’t heard of them the Nehe tutorials were the definitive free tutorials for learning OpenGL. Michael has done an excellent job of writing comments for these tutorials.
11. Khronos OpenGL ES Page This is the OpenGL ES "homepage" on which you will find the reference manual, and lots of examples. Not specifically IPhone, but there are some great examples here and even a complete racing game BSD licensed.
12. Khronos OpenGL ES 1.x Step-By-Step Tutorials This page is from Imagination Technologies makers of the Iphone GPU, and it contains the Khronos tutorials converted to OpenGL ES and created for the PowerVR technology. Good to lean from especially as to how they load Pod files.
13. Zeus CMD OpenGL ES Tutorials This site contains 25 Great OpenGL ES Tutorials and they are extremely well paced, this was a site I learned alot from.
14. Typhoon Labs OpenGL ES Tutorials Another excellent set of OpenGL ES tutorials if you’re addicted to tutorials you might want to check these out too.
OpenGL ES 2.0 Resources
These are the OpenGL ES 2.0 resources you know so far, the Khronos OpenGL ES page above also includes information on OpenGL ES 2.0. You can see there aren’t many that i know of so if you know of some killer OpenGL ES 2.0 resources please link to them
15. The OpenGL ES Programming Book The code from this book has been updated to run on the iPhone and can be found here. Make sure you have a solid understanding of OpenGL (or OpenGL ES 1.x) before starting this book.
16. The OpenGL ES Shading Language This is a free pdf book from Khronos, and actually a really good read, and will teach you what you need to know, again don’t try this until you at least have some OpenGL understanding or your head may explode. Thanks to Bill Dudney one of the authors of iPhone SDK Development for pointing this out.
This is a quick video on getting started with iPhone OpenGL ES:
That’s it, if you know of some other great resources please share them.
Something I seem to be asked alot of on twitter is “What is the easiest way to make games for the iPhone?”. Usually from individuals who have developed games in Flash or using a program such as the windows Gamemaker. Game development using Objective-C and OpenGL ES is considerably more difficult.
In the past I’ve mentioned a few tools out there that allow you to create games visually which can speed up your game creation time considerably. The game engines I’ve mentioned are Unity 3d, Shiva, and iTGB. With Unity 3d and Shiva being both 3d game development tools. Now the problem most people have with these tools is the cost.
Well, I’ve found a game creation program that is even easier.. in fact much easier than those programs, and is free. While it only supports 2D game creation I’ve read that the ability to compile games for the iPhone and sell them in the app store using this program is imminent. This game creation program is known as Gamesalad. It has already been set up for the iPhone screen size so once the ability to compile games for the iPhone is added you won’t have to do any porting. There will apparently be a small cost for transferring the games to the iPhone, but I can’t imagine it being anywhere near the cost for the other aforementioned iPhone game engines.
Check out this video, and just see how easy it is (Please note that Cinammon is now known as Gamesalad, and has evolved considerably since this video was made).
Now performance is often an issue with these rapid game creation programs, but even though it’s still in beta and needs alot of polish (and of course the ability to compile for the iPhone) it could be worth learning especially if you’re new to programming as using these tools you can learn how to understand the logic of programming quickly.
So check out Gamesalad if you’re looking for a really easy way to create games.. coming soon for the iPhone.
Since there always seems to be so many people asking on forums about iPhone game engines, and keeping with the theme of my last two posts I thought I would start keeping a list.
Cocoas2D – 2D Game Engine, Open Source, LGPL
iTGB for 2D Games – 2D Game Engine, Commercial, Min. cost $500
OOlong Engine – 3D Game Engine, Open Source, MIT License
SIO2Engine – 3D Game Engine, Open Source, Payment or flash screen on game required
Ston3D for Iphone – 3D Game Engine, Commercial, Min. cost approx. $250 (based on current conversion rates)
Unity3D Engine – 3D Game Engine, Commercial, Min. cost $199 + $399 If you have any exprience using any of the above engines in development please post any opinions you have. If you know of any other 3D or 2D engines available for iPhone developers then please post below.
This list has been updated:
A look at 8 different