2013-10-21 32 views

回答

2

Game Center Programming Guide复制:

GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] init]; 
if (leaderboardRequest != nil) 
{ 
    leaderboardRequest.playerScope = GKLeaderboardPlayerScopeGlobal; // or GKLeaderboardPlayerScopeFriendsOnly 
    leaderboardRequest.timeScope = GKLeaderboardTimeScopeToday; // or GKLeaderboardTimeScopeWeek, GKLeaderboardTimeScopeAllTime 
    leaderboardRequest.identifier = @"Combined.LandMaps" // Name of the leaderboard 
    leaderboardRequest.range = NSMakeRange(1,10); // How many results to get 
    [leaderboardRequest loadScoresWithCompletionHandler: ^(NSArray *scores, NSError *error) { 
     if (error != nil) 
     { 
      // Handle the error. 
     } 
     if (scores != nil) 
     { 
      // Process the score information. 
     } 
     }]; 
} 

要为特定用户获取信息:

GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] initWithPlayerIDs: match.playerIDs]; 

在这两种情况下,用户的分数都存储在localPlayerScore和所有得分得分

然而排名可能有问题。您最多只能获得100分,因此如果排行榜非常大,则可能需要大量电话。 localPlayerScore确实包含排名值,但那只是相对于当前得分列表而已。基本上你必须遍历整个排行榜找到用户的位置。

+1

感谢您的答复 - 所以它似乎好像没有直接的方式是正确的?如果您通过使用“范围”进行迭代,我想在拨打电话时排名可能会发生变化。即你毫无疑问地为每个请求使用不同的范围?例如1-100,然后101-200等? – Greg

+0

是的。目前据我所知,这是唯一的方法。我认为他们正在稳步扩大图书馆的功能,以便将来可以添加它。 – littleimp

+0

我不认为需要迭代。我试图使用一个范围,只包括最高分,而排名属性正确地报告了本地玩家的等级(在这种情况下是10,远低于最高分) - 请参阅下面的答案 – Maiaux

1

关于您的问题的第二部分,GKScore的排名属性应该做的伎俩。 根据我的测试,即使玩家的分数超出了请求的范围,它也会根据指定用于加载排行榜分数的标准报告玩家等级。 请参阅下面的示例:

GKLeaderboard *board = [[GKLeaderboard alloc] init]; 
pbBoard.timeScope = GKLeaderboardTimeScopeAllTime; 
pbBoard.range = NSMakeRange(1, 1); 
pbBoard.identifier = @"myleaderboard"; 
[pbBoard loadScoresWithCompletionHandler: ^(NSArray *scores, NSError *error) { 
    if (error != nil) { 
     // handle the error. 
    } 
    if (scores != nil) { 
     GKScore* score = [board localPlayerScore]; 
     NSInteger rank = score.rank; 
     // do whatever you need with the rank 
    } 
}]; 
相关问题