This is the first post in my “Developing a game for the iOS and Windows Phone 7 Platforms at the same time” series. Yes, I am trying to think of a catchier name. Anyway, let me get on with it. This post will cover, as the title suggests, getting ready for developing a game on the iOS platform. At the end, you’ll have the basic Cocos2d game up and running.
Getting the tools
Before you can begin writing any code, it’s necessary to get your hands on the development SDK. Apple’s IDE is called XCode 4 and this include the iPhone SDK. There are two ways to get XCode 4.
- If you are a member of the iOS Developer Program, you can download XCode 4 for free. Obviously, this isn’t really free since you have to pay the $99/£69 membership fee. However, if you’re serious about developing for the iOS platform, this is money well spent. You’ll need to join this to test your apps on a real device and to publish it. I would like to point out this is an annual membership, so you’ll have to cough up the money each year.
- If you’re not willing to spend so much dough up front, that’s okay too. XCode is available to download from the Mac App Store for the small sum of $4.99/£2.99. You’ll need to join the afore mentioned iOS Developer Program in order to publish your app, so you’ll be paying a little more overall. As I mentioned, not joining the Developer program means you can’t run your app on a device, so you’ll be limited to the simulator. This will become important when it comes to testing the real world performance of your game.
I have XCode 4. Now what?
After downloading it (it’s a whopping 4GB) and installed it, you’ll need to get your hands on the Cocos2d framework. As I discussed in my initial post, this is a game development framework, that includes a powerful physics engine called Box2d. There are two downloads to make. The first is the framework itself. I’m using the 1.0.0 Beta version. You can then download XCode 4 templates. The installation of these adds some special project templates to XCode and this helps speed up development by giving you a simple, pre-canned game.
All done? Comfortable? Let’s begin!
First, fire up XCode 4. You’ll need to use Spotlight to find it, but keep in the dock after it launches. On a fresh installation, you won’t have any “Recent” projects.
Select “Create a new XCode project” from the “New Project” dialog, select the cocos2d category from the iOS list on the left hand side. You should see the list of possible templates. Since I’m going to use Box2D, select that one and hit “Next”
Next you’ll be asked to enter the name of the App and the “Company Identifier”. For this, I just use my name, so enter yours here. I’m also calling the game “Bouncy”. Don’t worry about this right now as it doesn’t have to be the actual name of your app when you come to publish it. The “Bundle Identifier” value is made up of this name plus your company name and you’ll need this later on so you can put your app onto a real device and eventually publish your app.
Next you need to choose where to save the XCode project files. Choose a location that’s suitable. I typically create a folder called Development under my home account and put my project there. This way there are in one place. XCode should then present you with the created project, all populated with the necessary files.
Use the “Run” button or CMD-R to execute the project. XCode will start compiling the files, which can take a few seconds depending on your machine. It will then launch the iPhone Simulator and you should see something like this after the splash screen disappears. As it says, tap the screen a few times using the mouse pointer.
Well done! You should now have a working iPhone game, albeit a simple, demo one. The steps in this post have essentially setup XCode and a basic game shell that we can build our actual game upon. In the next few posts, we’ll look at creating a world that has some basic physics and populating that world with some sprites and finally creating a level that is playable.