2012-11-07 69 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的檢索所有的成績對於每個秩的調查結果。

因此,我建議您存儲分數數組並重用它,即使它會犧牲您的排名準確性。 (並在一定的時間間隔或類似的東西刷新比分數組)

相關問題