今天为我的iPhone游戏添加了Openfeint功能。有不少相关设置,花了我不少时间;发上来希望能对大家有所帮助。完成以下步骤后,你应当能看到下面的Openfeint界面!

简介:Openfeint是一个在线游戏系统,用于iPhone或者iPad游戏计分、挑战、多人对战等。可以在官网免费下载它的SDK。
环境:Openfeint 2.5.1,XCode 3.2.3,iPhone SDK 4.0,Cocos 2d 0.94。
步骤:
1. 将下载好的Openfeint文件夹加入工程之中。
2. 移除其中不需要的文件夹
- 如果你的游戏只支持landscape或者只支持iPad,移除iPhone_Portrait文件夹
- 如果你的游戏只支持Portrait或者只支持iPad,移除iPhone_Landscape文件夹
- 如果你的游戏不支持iPad,移除iPad文件夹
3. 在Project Settings中,
- 选择Build页,Configuration设置为All Configurations
- 找到Other Linker Flags,设置为 -ObjC
- 确保Call C++ Default Ctors/Dtors in Objective-C被打了钩
4. 添加以下framework
* Foundation* UIKit* CoreGraphics* QuartzCore* Security* SystemConfiguration* libsqlite3.0.dylib (located in (iPhoneSDK Folder)/usr/lib/)* CFNetwork* CoreLocation* MapKit (if building with SDK 3.0 or newer)* libz.1.2.3.dylib (alternatively you can add a OF_EXCLUDE_ZLIB preprocessor definition)
5. 在工程的prefix.pch文件中加入
#import “OpenFeintPrefix.pch”
6. 使用.mm后缀名(而不是.m)
7. 在Openfeint官网下载offline configuration文件(你每次更改设置都需要重新下载)。将这个文件添加到工程当中。
8. 在应用中加入SampleOFDelegate.h文件
#import “OpenFeintDelegate.h”
@interface SampleOFDelegate : NSObject< OpenFeintDelegate >
- (void)dashboardWillAppear;
- (void)dashboardDidAppear;
- (void)dashboardWillDisappear;
- (void)dashboardDidDisappear;
- (void)userLoggedIn:(NSString*)userId;
- (BOOL)showCustomOpenFeintApprovalScreen;
@end
9. 加入SampleOFDelegate.mm文件
#import “OpenFeint.h”
#import “SampleOFDelegate.h”
#import “cocos2d.h”
@implementation SampleOFDelegate
- (void)dashboardWillAppear
{}
- (void)dashboardDidAppear
{
[[CCDirector sharedDirector] pause];
[[CCDirector sharedDirector] stopAnimation];
}
- (void)dashboardWillDisappear
{}
- (void)dashboardDidDisappear
{
[[CCDirector sharedDirector] resume];
[[CCDirector sharedDirector] startAnimation];
}
- (void)userLoggedIn:(NSString*)userId
{
OFLog(@”New user logged in! Hello %@”, [OpenFeintlastLoggedInUserName]);
}
- (BOOL)showCustomOpenFeintApprovalScreen
{
return NO;
}
@end
10. 在应用启动时加入以下代码;其中launchDashboard一句可以加在其它地方。
#import “OpenFeint.h”
// Initialize OpenFeint on the title screen after you’ve displayed any splash screens.
// OpenFeint will present a modal the first time it’s initialized to conform with apple regulations.
- (void)initializeOpenfeint
{
[OpenFeint initializeWithProductKey:yourProductKey
andSecret:yourProductSecret
andDisplayName:yourApplicationNameForUsers
andSettings:aDictionaryOfOpenFeintSettings // see OpenFeintSettings.h
andDelegates:aDelegateContainer]; // see OFDelegatesContainer.h
// You probably want to invoke this from a button instead of directly here.
[OpenFeint launchDashboard];
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[OpenFeint applicationDidBecomeActive];
}
- (void)applicationWillResignActive:(UIApplication *)application
{
[OpenFeint applicationWillResignActive];
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[OpenFeint applicationDidEnterBackground];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[OpenFeint applicationWillEnterForeground];
}