【问题标题】:How to get high scores from OpenFeint?如何从 OpenFeint 获得高分?
【发布时间】:2011-04-05 01:31:34
【问题描述】:

在他们的支持下,OpenFeint 给你这个,但我不太明白。如何获取排行榜数据,例如前 10 名并在我自己的 UI 中显示?

原文链接:http://www.openfeint.com/ofdeveloper/index.php/kb/article/000028

[OFHighScoreService getPage:1 forLeaderboard:@"leaderboard_id_string" friendsOnly:NO silently:YES onSuccess:OFDelegate(self, @selector(_scoresDownloaded:)) onFailure:OFDelegate(self, @selector(_failedDownloadingScores))];

- (void)_scoresDownloaded:(OFPaginatedSeries*)page
{
    NSMutableArray* highscores = nil;

    if ([page count] > 0)
    {
        if ([[page objectAtIndex:0] isKindOfClass:[OFTableSectionDescription class]])
        {
            // NOTE: In the following line, we access "[page objectAtIndex:1]" to retrieve high scores from
            // the global leaderboard.  Using "[page objectAtIndex:0]" would retrieve scores just for the local player.
            // Older versions of OpenFeint did not break this out into 2 sections.
            highscores = [(OFTableSectionDescription*)[page objectAtIndex:1] page].objects;
        }
        else
        {
            highscores = page.objects;
        }
    }

    for (OFHighScore* score in highscores)
    {
        // ...
    }
}
- (BOOL)canReceiveCallbacksNow
{
    return YES;
} 

【问题讨论】:

  • 你是如何做到这一点的。你能分享你的代码来从 openfeint 检索本地前 10 高分吗
  • 或解释如何做到这一点。对我来说只有一个分数正在更新......我想要前 10 名

标签: iphone objective-c openfeint leaderboard


【解决方案1】:

请求高分页面的代码是第一行,即:

[OFHighScoreService getPage:1 forLeaderboard:@"leaderboard_id_string" friendsOnly:NO silently:YES onSuccess:OFDelegate(self, @selector(_scoresDownloaded:)) onFailure:OFDelegate(self, @selector(_failedDownloadingScores))];

您将此行放在要开始查询高分的地方。您可以根据需要更改页码。一旦检索到高分页面,就会调用回调_scoresDownloaded。该示例向您展示了如何遍历 highscores 数组中的 OFHighScore 对象。您可以用您自己的代码替换评论 // ... 以向玩家显示分数,或其他任何内容。

(如果出现错误_failedDownloadingScores 被调用;您应该实现它以显示错误。)

【讨论】:

  • 啊,这很有意义,所以我只需要将 nsmutablearray 高分放入表格中?让我困惑的是,如果你喜欢它有多个部分,我怎么能做到这一点,它包含玩家姓名、他们的分数和排名。我从来没有使用过像这样有多个部分的数组,我将如何显示它?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-22
  • 2021-10-03
  • 1970-01-01
  • 1970-01-01
  • 2017-12-21
  • 1970-01-01
相关资源
最近更新 更多