Thursday, August 6, 2009

Using Cocos 2D MyFirstGame

I've recently updated my version of Cocos2D to the new 0.8 rev for a new game I'm working on with a colleague of mine. I was pleasantly surprise to see many changes, some of which I had to do in the previous version I was using which I was dreading about having to merge back in this version. For example, the original event handler used to only take a CocosNode, which is not always convenient especially since there was a perfectly good interface (protocol) for event handling. In my own version, I had changed it so that you could pass in (id ) and did some refactoring to have the TouchEventsDelegate in its own .m file.

I was a bit surprised to see the exact file name already created when I opened up the new Cocos2D, at first I thought I was looking at the wrong branch. They also up the ante by removing the the event handlers from the Director, which was a good change (single responsibility principle). I don't always feel well qualified to be looking through Objective-C code, I feel my IQ drops a few point every time I try to design with Objective-C simply because I'm spending more time then I normally would thinking about syntax. Looking through the new version, I'm at least relieve to see some decent improvement. Once I spend more time on it, I'm sure I will find some holes here and there. After all, there's no perfect framework.

My first gripe is that I had went through the trouble of creating a cocos2d template type so I could quickly create projects using the wizard. At the time there was a template for one specific version 0.6.? but when I moved to 0.7.1 I had to spend some time fixing it up. I didn't feel like doing this again, especially since I had heard that MyFirstGame was there ready for you to use! MyFirstGame is a very simple app with all the static link libraries (which I didn't have before) and a Hello World type construct. The only problem I really had is that I truly loath it's location (test/samples/MyFirstGame). I wanted to have quick access to this projects, so I moved it to the root of my directory structure. Unfortunately now all my files for my static link project were in the wrong directory, this would be simple enough for me to fix in Visual Studio, but in XCode, well I don't want to call it tricky, it's just a bit different. Once you know how to do it, it's really no more difficult than Visual Studio.

Once this was all done (drag/drop the source file on the target's compile sources), I was finally able to recompile my project from my new location. Grrr, why does the Active SDK only list 3.0 as a valid SDK? To fix this I brought up the info for the projects and went under the build tab. From here, I did a quick search for SDK (that search box is awesome! I wish Visual Studio would have something similar), and I found Base SDK set to IPhone Device 3.0, I just changed this option to 2.2 and finally had option to access all my usual SDK.

Now I'll go back and try to work on Templatizing Cocos2D again. Although I think I found some good advice here for it : http://iphonesdkdev.blogspot.com/2009/01/xcode-template-for-cocos2d.html so this should be easier than my last time where I was going blindly through this process. To be fair, doing wizards for Visual Studio is not fun to do either.