1

我正在尝试使用 Game Center 在我的游戏中制作排行榜。我像这样发布高分:

GKScore *myScoreValue = [[[GKScore alloc] initWithCategory:@"grp.high_scores"] autorelease];
    myScoreValue.value = self.game.scoreMeter.score;

    NSLog(@"Attemping to submit score: %@", myScoreValue);

    [myScoreValue reportScoreWithCompletionHandler:^(NSError *error){
        if(error != nil){
            NSLog(@"Score Submission Failed");
        } else {
            NSLog(@"Score Submitted");
            id appDelegate = [[UIApplication sharedApplication] delegate];
            [appDelegate displayLeaderBoard:nil];
        }

    }];

我看到“提交分数”符合预期,它打开了 Game Center 排行榜视图,但它只是显示“没有分数”

我知道其他人说您至少需要两个帐户,但我已经尝试了三个。

对于每个帐户,游戏都会在 Game Center 应用程序中为他们显示,当我查询前十名时:

- (void) retrieveTopTenScores
{
    GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] init];
    if (leaderboardRequest != nil)
    {
        leaderboardRequest.playerScope = GKLeaderboardPlayerScopeGlobal;
        leaderboardRequest.timeScope = GKLeaderboardTimeScopeAllTime;
        leaderboardRequest.range = NSMakeRange(1,10);
        [leaderboardRequest loadScoresWithCompletionHandler: ^(NSArray *scores, NSError *error) {
            if (error != nil)
            {
                NSLog(@"Error grabbing top ten: %@", error);
            }
            if (scores != nil)
            {
                NSLog(@"Top ten scores: %@", scores);
            }
        }];
    }
}

每个用户只能看到自己的分数。

那么为什么排行榜是空的,为什么每个用户只能看到自己的分数呢?

4

2 回答 2

0

沙盒有时会很乱,但让我问你这个。你self.game.scoreMeter.score是int吗?

如果是这样,请尝试这样做:

myScoreValue.value = [[NSNumber numberWithInt:self.game.scoreMeter.score] longLongValue];

用于设置 GKScore 对象的值。让我知道它是否改变了什么。

于 2012-07-28T21:28:39.577 回答
-1

好吧,事实证明您需要使用开发人员沙盒帐户登录游戏中心才能正常工作

于 2012-08-02T04:09:46.283 回答