如何使用 Google Play Services C++ 实现前 10 名排行榜
How to implement top 10 leaderboard using Google Play Services C++
我们正在为 Android 和 iOS 设备开发一款排行榜前 10 名的游戏。
该游戏是使用 cocos2d-x.
在 C++ 上编写的
我找到了获取当前用户分数的方法,但没有任何方法可以获取其他用户的分数或分数列表。
是否可以为使用 Google Play 服务的用户列表获取分数?
我会查看此处记录的 loadTopScores 函数:
可以使用 ScorePage 来完成。
ScorePage 是一个单一的数据结构,允许您访问分数数据。
数据包括排行榜 id、开始、时间跨度、集合、上一个
得分页面标记,下一个得分页面标记,以及所有的向量
评分条目。
在 LeaderboardManager 中获取 ScorePage 的方法:
void FetchScorePage(...);
您必须从 LeaderboardManager
中获取 ScorePageToken
。你要找的函数是这样的:
ScorePage::ScorePageToken gpg::LeaderboardManager::ScorePageToken(
std::string const& leaderboard_id,
LeaderboardStart start,
LeaderboardTimeSpan time_span,
LeaderboardCollection collection) const
它允许您获得一个令牌,供您将其输入 gpg::LeaderboardManager::FetchScorePage
或 gpg::LeaderboardManager::FetchScorePageBlocking
。它的签名是这样的:
void gpg::LeaderboardManager::FetchScorePage(
ScorePage::ScorePageToken const& token,
uint32_t max_results,
FetchScorePageCallback callback)
它的用法是这样的:
auto token = gameServices->Leaderboards().ScorePageToken("LEADERBOARD-ID", TOP_SCORES, SOCIAL, ALL_TIME);
gameServices->Leaderboards().FetchScorePage(token, 10,
[=] (const gpg::LeaderboardManager::FetchScorePageResponse& response) {...});
每个页面最多 return 25 个分数条目,但您可以使用函数 NextScorePageToken
和 PreviousScorePageToken
浏览整个排行榜(在您的情况下,这不是必需的,因为您只想要前 10 名)。
我们正在为 Android 和 iOS 设备开发一款排行榜前 10 名的游戏。
该游戏是使用 cocos2d-x.
在 C++ 上编写的我找到了获取当前用户分数的方法,但没有任何方法可以获取其他用户的分数或分数列表。
是否可以为使用 Google Play 服务的用户列表获取分数?
我会查看此处记录的 loadTopScores 函数:
可以使用 ScorePage 来完成。
ScorePage 是一个单一的数据结构,允许您访问分数数据。 数据包括排行榜 id、开始、时间跨度、集合、上一个 得分页面标记,下一个得分页面标记,以及所有的向量 评分条目。
在 LeaderboardManager 中获取 ScorePage 的方法:
void FetchScorePage(...);
您必须从 LeaderboardManager
中获取 ScorePageToken
。你要找的函数是这样的:
ScorePage::ScorePageToken gpg::LeaderboardManager::ScorePageToken(
std::string const& leaderboard_id,
LeaderboardStart start,
LeaderboardTimeSpan time_span,
LeaderboardCollection collection) const
它允许您获得一个令牌,供您将其输入 gpg::LeaderboardManager::FetchScorePage
或 gpg::LeaderboardManager::FetchScorePageBlocking
。它的签名是这样的:
void gpg::LeaderboardManager::FetchScorePage(
ScorePage::ScorePageToken const& token,
uint32_t max_results,
FetchScorePageCallback callback)
它的用法是这样的:
auto token = gameServices->Leaderboards().ScorePageToken("LEADERBOARD-ID", TOP_SCORES, SOCIAL, ALL_TIME);
gameServices->Leaderboards().FetchScorePage(token, 10,
[=] (const gpg::LeaderboardManager::FetchScorePageResponse& response) {...});
每个页面最多 return 25 个分数条目,但您可以使用函数 NextScorePageToken
和 PreviousScorePageToken
浏览整个排行榜(在您的情况下,这不是必需的,因为您只想要前 10 名)。