0

我一直在游戏中心上努力工作。我已经测试了很多代码,我已经数不清了。我也很想知道如何自动提交分数这是我使用过的一些代码,但我不确定这是否会有所帮助

-(IBAction)showleaderboard:(id)sender{
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController   alloc]init];
if (leaderboardController !=NULL) {
    leaderboardController.category = self.currentLeaderboard;
    leaderboardController.timeScope = GKLeaderboardTimeScopeAllTime;
    leaderboardController.leaderboardDelegate = self;
    [self presentModalViewController:leaderboardController animated:YES];
}

}
-(void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController{
[self dismissModalViewControllerAnimated:YES];
[viewController release];

}


-(IBAction)showAchivementLeaderboard:(id)sender{
GKAchievementViewController *achivements = [[GKAchievementViewController alloc]init];
if (achivements !=NULL) {
    achivements.achievementDelegate = self;
    [self presentModalViewController:achivements animated:YES];
}
}
-(void)achievementViewControllerDidFinish:(GKAchievementViewController *)viewController{
[self dismissModalViewControllerAnimated:YES];
[viewController release];

}

self.currentLeaderboard= kEasyLeaderboardID;
if ([gameCenterManager isGameCenterAvailible]) {
   self.gameCenterManager= [[[GameCenterManager alloc] init] autorelease];
    [self.gameCenterManager setDelegate:self];
    [self.gameCenterManager authenticateLocalUser];
}else{

    UIAlertView *openURLAlert = [[ UIAlertView alloc] initWithTitle:@"Game Center turned    off" message:@"You are not connected to game center." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [openURLAlert show];
    [openURLAlert release];
}
4

1 回答 1

1

要报告分数,您需要使用 GKScore,如下所示;

GKScore *scoreReporter = [[GKScore alloc] initWithCategory:self.gameCategory.leaderboardString];
scoreReporter.value = score;

[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
    if (error != nil) {

        [[KYTGlobals instance] storeScore:score forCategory:self.gameCategory.leaderboardString];

        }
 }];

上面的代码使用您已经在游戏中心为您想要报告分数的类别设置的标识符分配并初始化一个 GKScore 对象。您更新分数的值,然后使用 reportScoreWithCompletionHandler 确保测试错误,以便您可以存档分数并稍后报告。

于 2012-07-27T08:03:30.607 回答