We just started integrating OpenFeint into Drop Dead, the Cocos2D-iPhone game we released towards the end of last year. The process was somewhat grueling, given that Open Feint’s instructions, in my opinion, are really lacking in the clarity needed for someone doing this for the first time. Obviously I was able to find several resources online:
But those are out of date at this point – OpenFeint is now up to version 2.10 and Cocos2D is at 0.99.5. So, after all the time we put into getting OpenFeint to initialize properly, we decided to throw together a template to help get you started with the process! We took the Cocos2D Hello World example, set it to be in portrait orientation, and put together an XCode project (using XCode 3.2.5, not 4.0 yet). Source code after the break! Click to download the template!
You will have to change a couple things – first, obviously, you need an OpenFeint account and an application that you’ve set up. Then, in Cocos2DOpenFeint.mm, modify these lines:
[OpenFeint initializeWithProductKey:@"YOUR_KEY" andSecret:@"YOUR_SECRET_KEY" andDisplayName:@"YOUR_APP_NAME" andSettings: settings andDelegates:delegates];
and replace it with the product key, secret key, and display name of YOUR app, of course! We’ve also set you up with some really bare bones delegates for OpenFeint callbacks for Challenges, Notifications, and “Bragging” on social networks.
As a side note, you will only see the “Enable OpenFeint” screen until you click one of the buttons on that screen – after that, you have to delete the app from the Simulator or your device to see it again.
Obviously this is just a starting point for OpenFeint – you’re going to want to actually use the functionality at some point. Here are just a couple of the API’s you may want to use to help get you started:
- Submit a Score
[OFHighScoreService setHighScore:score forLeaderboard:@"leaderboardId" onSuccess:OFDelegate() onFailure:OFDelegate()];
- Unlock an Achievement
[OFAchievementService unlockAchievement: @"achievementId" onSuccess: OFDelegate() onFailure: OFDelegate()];
- Check if the user has opted-in for OpenFeint
Hope this has been helpful – let us know what you think and what else should be added! Click to download the template!