Monday, January 16, 2012

How to run "Puff Puff 1.1" in iOS5 Simulator?

Thanks to 6thMega (Note: site still down when checked 25/11/2012) who generously published source code of their game "Puff Puff" Version 1.1. I have downloaded the source code for a while but wasn't able to let it compile at all.

The game uses Cocos2D for iPhone (Version 0.99.04) and OpenFeint, and it's written in C++.

This week after I finally worked out the fix for the problem mentioned in this old post "Error "Sending 'ccColor4B' (aka 'struct_ccColor4B') to parameter of incompatible type 'CIColor *'"", plus the knowledge about upgrading from chapter 7 of Steffen's book, I decided to give it another go.

It was quite challenging and a bit frustrating at the beginning. I was also stuck with "OpenFeint" problem for a long time - until I later decided to completely remove/disable it and that makes everything a lot easier!

So the notes below is only about how to modify the downloaded "Puff Puff 1.1" code so that it can compile and run in iOS5 simulator (with sound!!) under Xcode 4.2. Sorry I can't answer any question about the code, a more suitable place to discuss that would be at this post on cocos2d forum.

Please let me know if you found any problem or got any other information to share!



Step 1. Download the Puff Puff v1.1 source code from this link on 6thMega web site.

Step 2. Unzip it (as shown below) and double click on the "PuffPuffV.xcodeproj" file to open the project in Xcode.

Step 3. Let's fix all the frameworks and libraries first. With "Puff Puff" selected as "Targets" (middle of screen), select "Summary" tag (right hand side) and then scroll down to the bottom of the right hand side panel. You should see as below, a few missing frameworks/libraries shown in red colour under "Linked Frameworks and Libraries"

Using the "+" and "-" button we are going to fix them one by one. Starting with the "CFNetwork.framework", click "+", locate it from the list and then click "Add".

After it's added, you can now highlight the old, not working one (in red colour) and click "-" to remove it.

Repeat this until all of the red ones are gone. However, one of them called "libz.1.2.3.dylib" no longer existed and I can only find this "libz.1.2.5.dylib". As the name is quite similar with only minor difference in the version number, this should be the best choice. Note: please ignore the hint box as it's showing details of a different file while my mouse was over it

Step 4. Scroll back to the top, select "Build Settings" tab, and change all the "Base SDK" to "Latest iOS(iOS 5.0)"

Step 5. We can now start changing the files. Find "PuffPuffAppDelegate.mm" and look for this line as shown below. Either remove it or disable it by adding "//" at the front.

[PlayHaven preloadWithPublisherToken:@"token" testing:NO];


Step 6. If you try to "Build" now you will get quite a lot of errors. Let's start by fixing the easiest one - the "ccColor4B" problem I mentioned in this old post.


+ (id) layerWithColor:(ccColor4B)color
{
return [[[self alloc] initWithColor:color] autorelease];
}


There should be 2 of them, one in "cocos2d sources -> cocos2d -> CCLayer.m" and other in "GameScene.mm".

The fix is as below, change to as below:

+ (id) layerWithColor:(ccColor4B)color
{
return [[(CCColorLayer*)[self alloc] initWithColor:color] autorelease];
}


Step 7. Next we want to remove/disable "OpenFeint" - mainly because I can't get it to work. If anyone has better idea or know how to fix it, please let me know and we can then probably skip this whole step :-) ...

There are quite a few things to remove, so I am using "Step 7-x" as below to make it easier to follow.

Step 7-1. Highlight the 2 OpenFeint folder/file as shown below and select "Delete" to remove it.

At the next screen as shown below, click on "Delete" to remove all files.

Step 7-2. Remove all the imports for OpenFeint related header files. As shown below the line has to be removed or add "//" at the front to disable it. There's a few of them as listed below:

Classes -> Scenes -> MenuScene.mm - remove '#import "OpenFeint.h"'
Classes -> Scenes -> GameScene.mm - remove '#import "OFHighScoreService.h"'
Classes -> Scenes -> SplashScene.h - remove '#import "OpenFeint.h"' and '#import "OpenFeintSettings.h"'
Other Sources -> PuffPuffV_Prefix.pch - remove '#import "OpenFeintPrefix.pch"'
Classes -> PuffPuffAppDelegate.h - remove '#import "OpenFeintDelegate"' and '#import "OFNotificationDelegate.h"'


Step 7-3. Since last step ends with the file PuffPuffAppDelegate.h, might as well remove the "OFCallbackable" at the end. Don't forget you also have to remove the "," too and DON'T remove the closing bracket ">" after that. Be careful!

Step 7-4. Disable "InitializeOpenfeint()". As below, in Classes -> Scenes -> MenuScene.mm, disable the whole block inside the method "InitializeOpenfeint()".

Also, inside Classes -> Scenes -> SplashScene.mm, remove or disable the following line by adding "//" at the front in "aaa" method.

[self initializeOpenfeint];

Step 7-5. As shown below in Classes -> Scenes -> MenuScene.mm, remove the highlighted line about OpenFeint launchDashboardWithHighscorePage.


Step 7-6. Almost there. Next in Classed -> PuffPuffAppDelegate.mm, as shown below, remove or disable the 2 highlighted lines starting with "[OpenFeint userDidApproveFeint:"

Also in same file, completely remove or disable the 2 methods causing compilation error as shown below.

Step 7-7. As shown below, in Classes -> GameScene.mm remove or disable the line "[OFHighScoreService ...."

That's it! As below, you should be able to compile and play the game in iOS5 simulator, and the music is really cool too! Enjoy!




[Updated 5/4/2012]
As the 6thMega web site is currently down (see this post), I have uploaded the copy of PuffPuff V1.1 I downloaded last November to this link. Please note that the copyright still belongs to 6thMega, and this is just a temporarily work around while the 6thMega site is unavailable. Please let me know if you have problem with the link or any other issue with this sharing. Thanks.

[Update 25/11/2012]
Tested in XCode 4.5 with iOS 6 simulator running in 4 inch Retina display (iPhone 5), other than the 2 black stripes on both side as shown below, the game still works! Unfortunately looks like the 6thMega site no longer exist....



0 comments:

Post a Comment