Tuesday, 17 January 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....



13 comments:

  1. I'm brand new to xCode and iOS, and needed an open source program to "test" for a masters class. It would have taken me days to figure all this out on my own, so THANK YOU!!!

    ReplyDelete
  2. hi, i found the download page of puff-puff is closed. i really want to read the source code. Would you be kind enough to share this code again. Thank you.

    ReplyDelete
  3. thanks for your hard works.

    ReplyDelete
  4. No worries, unfortunately the 6thmega site still down... I quite like their style, hope they can be back soon ( or as another company? ) and bring us more open source good quality work!

    ReplyDelete
  5. Hey guys,
    6thmega's site is still and I'd really like to see the source code! Could someone please post it or send it to me please?

    Thanks in advance

    ReplyDelete
  6. Hi, if you read the updated part, I have created a copy for puff puff 1.1 and provided the link above. That's the only one I have, sorry can't help with others.

    ReplyDelete
  7. Thanks! So I downloaded the source code and performed the modifications you mentioned above. Neither build errors, nor build warnings are mentioned by Xcode. It just says "build succeeded but the game iOS simulator does not appear!
    Any suggestions?

    Thanks in advance

    ReplyDelete
  8. Could be many reasons. Have to start from most basic ones if you don't mind-
    1. Have you ever successfully run any project in that machine (e.g. hello world) - to make sure you are familiar with the process.
    2. Is your scheme set to "PuffPuff -> iPhone x.x simulator"?
    3. Did you click on "Product -> Run" ?
    4. anything shown in the "debug" window?

    ReplyDelete
  9. Thank you so much, but I have not downloaded source code at this moment. This link may be broken. Can you help me other link to download.

    ReplyDelete
  10. Please see the latest update of the post, there's a link there to download the PuffPuff1.1 source. Just tested it, still working ok.

    ReplyDelete
  11. Link to source code is broken? Does anyone have it?

    ReplyDelete
    Replies
    1. Hi, if you read through the post again, you will find the link under "[Updated 5/4/2012]". Thanks

      Delete