2012-11-07 71 views
2

有没有办法让玩家的分数排名上升?即使分数不是他最好的?如何获得刚刚发布到GameCenter的分数排名?

[GKScore reportScoreWithCompletionHandler:]用于将评分发布到GameCenter,但其“等级”始终为零。只有在调用[GKLeaderboard loadScoresWithCompletionHandler:]时,'rank'值才有效,但是它的排名是今天/周/所有时间的最佳分数。

最好的地方是[GKScore reportScoreWithCompletionHandler:],使得'rank'值在从gamecenter返回时有效。

谢谢。

回答

1

AFIK没有这样的解决方案。 GameCenter仅存储玩家的最高分数。

Read this

所以,如果你真的想这样做,你有你自己的排名的球员。

  1. 检索排行榜上的所有分数。
  2. 检查当前得分的等级。下面

    -(void) findRankWithScore: (int64_t)score 
    { 
        GKLeaderboard *leaderboard = [[GKLeaderboard alloc] init]; 
    
        if (leaderboard != nil) { 
         leaderboard.category = @"YourCategory"; 
         leaderboard.timeScope = GKLeaderboardTimeScopeWeek; //or all time, day... pick one. 
    
         [leaderboard loadScoresWithCompletionHandler:^(NSArray *scores, NSError *error) { 
          int rank = 0; 
          if (error == nil && scores != nil) { 
           for (GKScore* refScore in scores) { 
            //NOTE: Retrieved score array is sorted already. 
            if (refScore.value <= score) { 
             rank = refScore.rank - 1; 
             if (rank < 1) { 
              rank = 1; 
             } 
             break; 
            } 
           } 
           //show the rank to player. using delegate, notification, popups etc... 
    
          }else { 
           //handle errors 
          } 
         }]; 
        } 
    } 
    

- 样品代码此外,它花费了很多从GameCenter的检索所有的成绩对于每个秩的调查结果。

因此,我建议您存储分数数组并重用它,即使它会牺牲您的排名准确性。 (并在一定的时间间隔或类似的东西刷新比分数组)

相关问题