有谁知道如何在Cocos2d 中集成游戏中心.请告诉我步骤,以便我可以将其集成到我的游戏中.
Is there any one who knows how to integrate game center in Cocos2d. Please tell me steps so i can integrate that in my Game.
更新:
我创建了自己的 Helper 类,适用于所有类型的应用程序(还有 Cocos2D 1 和 2+)https://github.com/alexblunck/ABGameKitHelper
I created my own Helper Class that works with all kind of Apps (also Cocos2D 1 & 2+) https://github.com/alexblunck/ABGameKitHelper
您好,我建议您使用 Steffen Itterheim 的 GKHelper 课程!我为您上传了 GKHelper.h/GKHelper.m:http://www.cl.ly/7ReW
Hi I suggest you use GKHelper Class from Steffen Itterheim! I uploaded the GKHelper.h / GKHelper.m for you: http://www.cl.ly/7ReW
然后按照以下说明操作:
Then follow these instructions:
//0.0 将 GameKit 框架添加到项目中(如果您不知道如何执行此操作,请询问;)
//0.0 Add GameKit Framework to Project (Ask If you don't know how to do this ;) )
//0.更改[window addSubview:viewController.view];"在 AppDelegate.m 中://如果你使用的是 0.99.5 之后的任何 cocos2D 版本,请执行此操作:
//0. Change "[window addSubview: viewController.view];" in the AppDelegate.m to: //Do this if you're using any release of cocos2D after 0.99.5:
window.rootViewController = viewController;
//1.将 Gamekithelper.h/.m 添加到项目中
//1. Add Gamekithelper.h / .m to project
//2.在给定的标头中包含以下委托:
//2. Include following delegate in given header:
<GameKitHelperProtocol>
//3.将委托方法添加到 .m
//3. Add Delegate Methods to .m
//4.将 GameKitHelper 添加到场景":
//4. Add GameKitHelper to "Scene":
GameKitHelper *gkHelper = [GameKitHelper sharedGameKitHelper];
gkHelper.delegate = self;
[gkHelper authenticateLocalPlayer];
//将分数添加到排行榜:
//Adding score to leaderboard:
GameKitHelper *gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper submitScore:scoreValue category:@"LeaderboardID"];
//添加成就完成:
GameKitHelper *gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper reportAchievementWithID:@"AchievementID" percentComplete:100];
这些是第 3 步中提到的需要添加的委托方法:
These are the delegate Methods that need to be added mentioned in Step #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);
}