【问题标题】:How can I get users' times & rankings for a specific leaderboard & timescope from Game Center?如何从 Game Center 获取特定排行榜和时间范围的用户时间和排名?
【发布时间】:2013-10-29 10:03:44
【问题描述】:

对于 Apple 的游戏中心 api,我将如何请求和取回特定排行榜和时间范围的本地用户时间和排名?

  • 对于给定的 TimeScope,对于排行榜 X(即指定棋盘 - 例如 Level12_BestTime)
  • 获取返回的本地玩家当前: a) 时间12.3秒 b) 排名(与朋友)例如12日 c) 排名(所有玩家)例如第 123 名

【问题讨论】:

    标签: ios game-center leaderboard


    【解决方案1】:

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

    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
        }
    }];
    

    【讨论】:

      【解决方案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 中,所有分数都存储在 scores 中。

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

      【讨论】:

      • 感谢您的回复 - 所以似乎没有直接的正确方法?如果您确实通过使用“范围”进行了迭代,我想在您拨打电话时排名可能会发生变化?即,毫无疑问,您对每个请求使用不同的范围?例如1-100,然后是 101-200 等等?
      • 是的。目前据我所知,这是唯一的方法。我认为他们正在稳步扩展库的功能,因此将来可能会添加它。
      • 我认为不需要迭代。我尝试使用仅包括最高分的范围,并且 rank 属性正确报告了本地玩家的排名(在这种情况下为 10,远低于最高分) - 请参阅下面的答案
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-01
      • 1970-01-01
      相关资源
      最近更新 更多