【发布时间】:2011-06-08 11:34:46
【问题描述】:
有谁知道如何在Cocos2d 中集成游戏中心。 请告诉我步骤,以便我可以将其集成到我的游戏中。
【问题讨论】:
标签: cocos2d-iphone game-center
有谁知道如何在Cocos2d 中集成游戏中心。 请告诉我步骤,以便我可以将其集成到我的游戏中。
【问题讨论】:
标签: cocos2d-iphone game-center
更新:
我创建了自己的 Helper 类,适用于所有类型的应用程序(还有 Cocos2D 1 和 2+) https://github.com/alexblunck/ABGameKitHelper
您好,我建议您使用 Steffen Itterheim 的 GKHelper 课程!我为你上传了GKHelper.h / GKHelper.m:http://www.cl.ly/7ReW
然后按照以下说明操作:
//0.0 将 GameKit 框架添加到项目中(如果您不知道如何执行此操作,请询问;)
//0.更改“[window addSubview:viewController.view];”在 AppDelegate.m 中: //如果你使用的是 0.99.5 之后的任何 cocos2D 版本,请执行此操作:
window.rootViewController = viewController;
//1.将 Gamekithelper.h / .m 添加到项目中
//2.在给定的标头中包含以下委托:
<GameKitHelperProtocol>
//3.将委托方法添加到 .m
//4.将 GameKitHelper 添加到“场景”:
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);
}
【讨论】:
您可以使用 GamKit 框架。游戏中心对于管理您的在线游戏和游戏分数也非常强大。使用游戏中心,您可以创建两种类型的游戏
1:实时比赛(实时赛车) 2:Turn Base Matchs(在线纸牌游戏)
我正在与您分享 RaywenderLich 的链接:
回合制比赛http://www.raywenderlich.com/5480/beginning-turn-based-gaming-with-ios-5-part-1
【讨论】:
虽然 Alexander Blunck 的回答是合理的,但对于早期版本的 iOS(例如 3.2),以下行会出错,这不是您想要的。
window.rootViewController = viewController;
如果你打算使用 Steffen 的代码(呃),那么你可能想要添加一个方法来直接设置 ui 视图控制器,而不是让它假设它可以通过 UIApplication 抓取。
【讨论】: