我试过谷歌,但我找不到一个看起来合法的。我有游戏中心所有设置只需要获得排行榜和成就。任何建议都会很好。谢谢。另外,既然我将得分保存为字符串,那么我是如何把它放在排行榜中的呢?
答案 0 :(得分:1)
将排行榜代表添加到图层类。
@interface MyMainMenu : CCLayer<GKLeaderboardViewControllerDelegate>
根据您的需要显示排行榜。
-(void)displayLeaderboard
{
GKLeaderboardViewController *leaderboardViewController = [[GKLeaderboardViewController alloc] init];
leaderboardViewController.leaderboardDelegate = self;
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[app.navController presentModalViewController:leaderboardViewController animated:YES];
}
添加这两个排行榜代表功能
#pragma mark GameKit delegate
-(void) achievementViewControllerDidFinish:(GKAchievementViewController *)viewController
{
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[app.navController dismissModalViewControllerAnimated:YES];
}
-(void) leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[app.navController dismissModalViewControllerAnimated:YES];
}
提交分数:
[[GameCenterManager sharedGameCenterObject] reportScore:score forCategory: kLeaderboardID];
使用GKTapper示例中的GameCenterManager.m类(请参阅您的apple sdk示例)。
以下是从偏好中获取价值的代码: //从pref
获取保存的值int highScore = [[[NSUserDefaults standardUserDefaults] objectForKey:@"HighScore"] intValue ];
答案 1 :(得分:1)
有一整章关于游戏中心编程,带有示例代码,在Itterheim&amp; Loew的书“用iOS5学习Cocos2d游戏开发”。也是Strougo&amp ;;的“学习Cocos2d” Wenderlich有一章有工作代码。