iOS is the operating system used by iPhones, iPads and iPod Touch devices. If you want to create iOS apps you’re going to have to learn Objective-C, which is Apples object-oriented version of C. The hardest part for me when I started learning Objective-C was sorting through the information available. How was I to know where to focus? What could I defer for now and learn later? You can only learn so much stuff at once.
My tutorials are going to focus on creating a re-usable template for creating a game. This game will have chapter and level selection much like Angry Birds or Cut the Rope. You know the ones, you unlock levels and earn stars. Time to learn to walk before we can crawl.
To get started you will need:
- A Mac
- An iOS developer account from developer.apple.com (USD$99/year)
- A copy of Xcode installed on your Mac
Xcode is the development suite used to create iOS applications, or in other words, a text-editor and app content manager on steroids. Once you’re signed up as an Apple iOS Developer you will be able to download Xcode from the Member Center. The current version of Xcode is version 4. Version 3 is so last year.
Time for some quick theory work before we dive into the practical.
What are Classes?
Classes are reusable pieces of code that perform a specific function. In Objective-C a class is split into two files. A header file which has a file extension of .h and an implementation file with a file extension of .m. The reason for the split is to simplify how you use an existing class. You don’t necessarily need to know how a class does something, you just need to know how to ask it to do something. This means that when using an existing class you will look at the .h file and study the interface to determine how to use it.
What are Frameworks?
Collections of classes are generally referred to as Frameworks. Cocos2d is a framework with classes useful for games in particular. As I mentioned before we’re going to create a template that can be re-used as a starting point for a game, so we’re going to use Cocos2d. To create games you don’t normally use the Interface Builder supplied with Xcode, so I won’t cover its usage. Instead the programming is done by hand. Go ahead and download the latest unstable version of cocos2d-iphone, by the time you release your game it’ll probably be the stable version!
Sweet. Now you’ve got Xcode, a Cocos2d tar.gz file and no idea what to do next.
You don’t need to install Cocos2d, it’s just a bunch of class files you can literally copy and paste into the same directoy of your iOS app. It is however much preferred if you can at least install the Xcode templates to make your life easier. I won’t cover this as the tutorial to install those templates exists here, section 3 shows you how.
At this point I’m assuming you have your cocos2d templates installed. If you do, create a new project in Xcode (File > New > Project) and select the cocos2d_box2d template. If you didn’t manage to get that far don’t worry, just download and extract this file I’ve prepared earlier. Double click Testing.xcodeproj and you’re up to speed.
How to run an app in the iPad or iPhone simulator
In the top left of Xcode you have a play button, stop button and target device drop down. If you press play and it doesn’t work it’s likely that the project has a different deployment target than you have installed. For example I’m using iOS5 and your Xcode might only have up to 4.3. You will need to select the blue (top left) top level Testing project then change the deployment target version to 4.3 before it will work.
Hopefully now you’re at a point where you can see text in the iOS simulator saying ‘Tap Screen’, try it.
That’s enough for part 1, stay tuned for the continuation where I’ll take you on a closer tour of Xcode.
If you liked this tutorial or found something wrong with it please let me know!
If you want to support my work and have an iPad please consider purchasing iSoccer *wink*