From today, I plan to write a series of articles on iOS game development in Objective-C using Cocos2D.
It’s kinda personal but let me be frank. While I was reading “Steve Jobs”, a big question came to my mind, “why should I even care about HTML5 and Flash?”
Steve Jobs worked hard innovating new user experience using the cutting edge technologies. Compared to that, using HTML5 and Flash means that I must be always following the latest technology one step behind or two or even more.
There is Corona SDK that updates frequently enough to catch up with technology advancements. But it is still behind native languages – Objective-C in case of iOS application development.
I realize that cross-platform-ness has it own raison d’etre and I will definitely follow it up with more articles but when I thought about the main topic for the rest of this year. I thought about Steve Jobs and his platform.
To develop for iOS, Objective-C should give me the most flexibility in terms of adopting new API, etc. If I don’t have any hang-ups, there is no reason to avoid it.
Probably, Corona SDK and Titanium Mobile can give better speed. But while reading “Steve Jobs”, I thought, “what’s the heck? Why don’t I just use Objective-C? Wouldn’t that give me the best performance?”
If that is the case, I should just use the iOS SDK. Why should I use Cocos2D?
In theory, logically correct thing should be correct. In real life, that is not always true.
I have limited time and resource. I had to make a trade off. So, I think of Cocos2D since it’s a framework written in Objective-C and it is for game developments.
It’s very easy to handle Sprite animation. It hides OpenGL details so you don’t have to deal with it. It is most well-known Objective-C game development framework.
There is Cocos2D-X which is C++ based. It supports Android development as well. But again, it’s a cross-platform development environment which means there might be some compromise I’d have to make. Having said that I’d like to pick up Cocos2D-X in my future articles.
How to install Cocos2D
You can download Cocos2D from here.
After extracting the file on your Mac, there will be a folder (i.e. cocos2d-iphone-1.0.1). Open the Terminal app and go to the folder. Then, execute the following script.
That’s all. You now have Cocos2D templates in your Xcode.
Let’s create a Cocos2D app
Start Xcode and create a new project by choosing one of the Cocos2D templates.
There are three choices:
|Tempalte name||Physics Engine|
Let’s choose the most basic one without any physics engine.
Enter your project name and specify where to store your project.
For unknown reason, “Identifier” remains “com.yourcompany”. I’m not certain if that is due to some issue in Xcode or Cocos2D. I just fixed it manually and there is no more issues.
Choose “iPhone 5.0 Simulator” and press CMD+R which builds the project and start the iPhone 5.0 simulator. If you are careful enough to examine the build result, you may find there are some deprecation warnings for [[UIDevice currentDevice] uniqueIdentifier]. Just ignore it for now. I believe future versions of Cocos2D will address that warning.
Once fully started, iPhone 5.0 simulator shows “Hello World”. Your project is fully built and running without a hitch.
I probably talk too much in the beginning. As mentioned, I was quite moved by “Steve Jobs” book.
Life is short and it’s most important you make full use of it.
Why should I just complain the slowness of HTML5 and Flash?
I work as a C++ developer and I am capable of handling Objective-C. I should just go for it.
So, I’d like to experiment with Cocos2D and write a series of articles on it.
By the way, the above sample project contains a lot of generated files.
Let’s look at the important ones one by one in the next article. Stay tuned.