有关如何在cocos2d中制作排行榜和成就的任何教程

时间:2012-07-20 07:36:14

标签: objective-c ios xcode cocos2d-iphone game-center

我试过谷歌,但我找不到一个看起来合法的。我有游戏中心所有设置只需要获得排行榜和成就。任何建议都会很好。谢谢。另外,既然我将得分保存为字符串,那么我是如何把它放在排行榜中的呢?

2 个答案:

答案 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有一章有工作代码。