有没有人知道如何在Cocos2d中集成游戏中心(Game Center)。 请告诉我具体步骤,这样我就可以将其集成到我的游戏中。
有没有人知道如何在Cocos2d中集成游戏中心(Game Center)。 请告诉我具体步骤,这样我就可以将其集成到我的游戏中。
更新:
我创建了自己的 Helper 类,可以与各种应用程序一起使用(包括 Cocos2D 1 和 2+)。https://github.com/alexblunck/ABGameKitHelper
嗨,我建议您使用 Steffen Itterheim 的 GKHelper Class!我已为您上传了 GKHelper.h / GKHelper.m:http://www.cl.ly/7ReW
然后按照以下说明操作:
//0.0 将 GameKit Framework 添加到项目中(如果您不知道如何执行此操作,请询问;))
//0. 在 AppDelegate.m 中将 "[window addSubview: viewController.view];" 更改为: //如果您使用的是 cocos2D 0.99.5 之后的任何版本,请执行此操作:
window.rootViewController = viewController;
//1. 将Gamekithelper.h/.m添加到项目中
//2. 在给定的头文件中包含以下委托:
<GameKitHelperProtocol>
//3. 将代理方法添加到 .m 文件
//4. 将 GameKitHelper 添加到 "Scene" 中:
GameKitHelper *gkHelper = [GameKitHelper sharedGameKitHelper];
gkHelper.delegate = self;
[gkHelper authenticateLocalPlayer];
//将分数添加到排行榜:
GameKitHelper *gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper submitScore:scoreValue category:@"LeaderboardID"];
//添加成就完成状态:
GameKitHelper *gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper reportAchievementWithID:@"AchievementID" percentComplete:100];
这些是在第3步中提到需要添加的委托方法:
#pragma mark GameKitHelper delegate methods
-(void) onLocalPlayerAuthenticationChanged
{
GKLocalPlayer* localPlayer = [GKLocalPlayer localPlayer];
CCLOG(@"LocalPlayer isAuthenticated changed to: %@", localPlayer.authenticated ? @"YES" : @"NO");
if (localPlayer.authenticated)
{
GameKitHelper* gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper getLocalPlayerFriends];
//[gkHelper resetAchievements];
}
}
-(void) onFriendListReceived:(NSArray*)friends
{
CCLOG(@"onFriendListReceived: %@", [friends description]);
GameKitHelper* gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper getPlayerInfo:friends];
}
-(void) onPlayerInfoReceived:(NSArray*)players
{
CCLOG(@"onPlayerInfoReceived: %@", [players description]);
}
-(void) onScoresSubmitted:(bool)success
{
CCLOG(@"onScoresSubmitted: %@", success ? @"YES" : @"NO");
}
-(void) onScoresReceived:(NSArray*)scores
{
CCLOG(@"onScoresReceived: %@", [scores description]);
GameKitHelper* gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper showAchievements];
}
-(void) onAchievementReported:(GKAchievement*)achievement
{
CCLOG(@"onAchievementReported: %@", achievement);
}
-(void) onAchievementsLoaded:(NSDictionary*)achievements
{
CCLOG(@"onLocalPlayerAchievementsLoaded: %@", [achievements description]);
}
-(void) onResetAchievements:(bool)success
{
CCLOG(@"onResetAchievements: %@", success ? @"YES" : @"NO");
}
-(void) onLeaderboardViewDismissed
{
CCLOG(@"onLeaderboardViewDismissed");
GameKitHelper* gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper retrieveTopTenAllTimeGlobalScores];
}
-(void) onAchievementsViewDismissed
{
CCLOG(@"onAchievementsViewDismissed");
}
-(void) onReceivedMatchmakingActivity:(NSInteger)activity
{
CCLOG(@"receivedMatchmakingActivity: %i", activity);
}
-(void) onMatchFound:(GKMatch*)match
{
CCLOG(@"onMatchFound: %@", match);
}
-(void) onPlayersAddedToMatch:(bool)success
{
CCLOG(@"onPlayersAddedToMatch: %@", success ? @"YES" : @"NO");
}
-(void) onMatchmakingViewDismissed
{
CCLOG(@"onMatchmakingViewDismissed");
}
-(void) onMatchmakingViewError
{
CCLOG(@"onMatchmakingViewError");
}
-(void) onPlayerConnected:(NSString*)playerID
{
CCLOG(@"onPlayerConnected: %@", playerID);
}
-(void) onPlayerDisconnected:(NSString*)playerID
{
CCLOG(@"onPlayerDisconnected: %@", playerID);
}
-(void) onStartMatch
{
CCLOG(@"onStartMatch");
}
-(void) onReceivedData:(NSData*)data fromPlayer:(NSString*)playerID
{
CCLOG(@"onReceivedData: %@ fromPlayer: %@", data, playerID);
}