我正在编写自定义排行榜,我只想知道玩家ID,他/她在排行榜上的位置。
我找到了这个帖子:Rank of Local authenticated player in All Time best in game center leaderboard
但是我在实施它时遇到了麻烦。这就是我所拥有的:
-(void) retrieveScoresForPlayers:(NSArray*)players
category:(NSString*)category
range:(NSRange)range
playerScope:(GKLeaderboardPlayerScope)playerScope
timeScope:(GKLeaderboardTimeScope)timeScope
{
if (isGameCenterAvailable == NO)
return;
GKLeaderboard* leaderboard = nil;
if ([players count] > 0)
{
//leaderboard = [[[GKLeaderboard alloc] initWithPlayerIDs:players] autorelease];
leaderboard = [[[GKLeaderboard alloc] initWithPlayerIDs:[NSArray arrayWithObject:[GKLocalPlayer localPlayer]]] autorelease];
}
else
{
leaderboard = [[[GKLeaderboard alloc] init] autorelease];
leaderboard.playerScope = playerScope;
}
if (leaderboard != nil)
{
leaderboard.timeScope = timeScope;
leaderboard.category = category;
leaderboard.range = range;
[leaderboard loadScoresWithCompletionHandler:^(NSArray* scores, NSError* error)
{
[self setLastError:error];
//[delegate onScoresReceived:scores];
if (_gkhDelegate != NULL) {
_gkhDelegate->onScoresReceived([self convertNSArrayOfGKScoresToCppVector:scores]);
}
}];
}
}
每当我打印等级时,无论实际数量如何,它始终为1。我怀疑它在查询中返回排名。如何返回排行榜中的绝对位置?
答案 0 :(得分:0)
看起来在收到分数后,它会调用onScoresReceived
委托方法并传入分数向量。
您将需要实现该委托方法,以便您可以获取分数和矢量的向量。如果需要,可以按分数对对象进行排序(不确定它们是否已经排序)。每个GKScore
都有一个player
属性,您应该可以对其进行比较。看看那个球员是否与你当地的球员相匹配。