2

我已经尝试谷歌它,但我找不到一个看起来合法的。我已经建立了所有游戏中心,只需要建立排行榜和成就。任何建议都会很好。谢谢你。另外,既然我已经将我的分数保存到一个字符串中,我该如何将它放在排行榜中?

4

2 回答 2

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 类(请参阅您的苹果 sdk 示例)。

这是从首选项中获取值的代码://从首选项中获取保存的值

int highScore = [[[NSUserDefaults standardUserDefaults] objectForKey:@"HighScore"] intValue ];
于 2012-07-20T07:52:16.613 回答
1

Itterheim & Loew 的《Learn Cocos2d Game Development with iOS5》一书中有一整章是关于游戏中心编程的,并附有示例代码。Strougo & Wenderlich 的“Learning Cocos2d”也有一章包含工作代码。

于 2012-07-21T00:42:21.137 回答