如何从Game Center中获取本地玩家的高分

时间:2014-02-18 19:09:13

标签: cocos2d-iphone game-center

努力下载并显示本地玩家在游戏中心显示的高分 - 当前代码显示为0,尽管得分为215

 GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] init];
    leaderboardRequest.playerScope = GKLeaderboardPlayerScopeGlobal;
    leaderboardRequest.timeScope = GKLeaderboardTimeScopeAllTime;
    leaderboardRequest.range = NSMakeRange(1,1);

    int64_t personalBest= (int64_t)(leaderboardRequest.localPlayerScore.value * 1000000);

    CCLabelTTF *HighScoreLabel = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"%lld",personalBest] fontName:@"MyScriptFont" fontSize:50.0];
    HighScoreLabel.positionType = CCPositionTypeNormalized;
    HighScoreLabel.position = ccp(0.65f, 0.7f);
    [self addChild:HighScoreLabel];

1 个答案:

答案 0 :(得分:0)

根据apple documentation,您需要调用loadScoresWithCompletionHandler来检索分数。所以在调整范围之后调用以下内容。

[leaderboardRequest loadScoresWithCompletionHandler: ^(NSArray *scores, NSError *error) {
            if (error != nil)
            {
                // Handle the error.
            }
            if (scores != nil)
            {
                // Process the score information.
            }
            }];