Domanda

Struggling to download and show the local players high score that's displayed on Game Center - the current code is showing 0 although score is 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];
È stato utile?

Soluzione

According to apple documentation you need to call the loadScoresWithCompletionHandler to retrieve the scores. So after making the range call the following.

[leaderboardRequest loadScoresWithCompletionHandler: ^(NSArray *scores, NSError *error) {
            if (error != nil)
            {
                // Handle the error.
            }
            if (scores != nil)
            {
                // Process the score information.
            }
            }];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top