我使用谷歌播放服务领先上传用户的得分。有没有一种方法来检索程序的用户的分数?
我使用的情况是,我想运行乘数玩家在其中具有上升和下降根据自己的胜平/失去了(有点像计算器声望)。我需要找回老分数上传修改后的新成绩。
我怎样才能做到这一点?我没有看到在这个教程的任何地方。
谢谢
从理论上讲,你可以通过做这样的事情:
gameHelper.getGamesClient().loadLeaderboardMetadata(this, false);
/**
* Called when the data is loaded
*/
@Override
public void onLeaderboardMetadataLoaded(int statusCode, LeaderboardBuffer leaderboards) {
// If the fragment is currently added to an activity
if (isAdded()) {
// There's been an error on leaderboards loading
if (statusCode != GamesClient.STATUS_OK) {
if (leaderboards != null) leaderboards.close();
// Error
return;
}
ArrayList<LeaderboardVariant> variants;
Iterator<Leaderboard> it = leaderboards.iterator();
while (it.hasNext()) {
Leaderboard leaderboard = it.next();
final String id = leaderboard.getLeaderboardId();
variants = leaderboard.getVariants();
// For each leaderboard
for (LeaderboardVariant variant: variants) {
if (variant.getCollection() == LeaderboardVariant.COLLECTION_PUBLIC &&
variant.getTimeSpan() == LeaderboardVariant.TIME_SPAN_ALL_TIME) {
int rawScore = (int) variant.getRawPlayerScore();
}
}
}
}
if (leaderboards != null) leaderboards.close();
}
......但现实是,你不能因为数据已经过时,在这里看到:Play games loadLeaderboardMetadata() returns outdated data
这可能是一个错误,但因为没有地方玩提交游戏的bug ...
无论如何,你为什么不保留您所提交的分数的本地副本?那岂不是更简单的方法来做到这一点?
[更新]看来你可以实现你想要使用loadCurrentPlayerLeaderboardScore代替loadLeaderboardMetadata方法是什么。这一个似乎没有返回过时的数据。检查它here
如果有人还在寻找解决方案,根据最新的Android版本,在上面的回答中描述的方法现在已经过时。
做到这一点的最新方法如下:
private LeaderboardsClient mLeaderboardsClient = Games.getLeaderboardsClient(this, googleSignInAccount);
private void updateLeaderboards(final String leaderboardId) {
mLeaderboardsClient.loadCurrentPlayerLeaderboardScore(
leaderboardId,
LeaderboardVariant.TIME_SPAN_ALL_TIME,
LeaderboardVariant.COLLECTION_PUBLIC
).addOnSuccessListener(new OnSuccessListener<AnnotatedData<LeaderboardScore>>() {
@Override
public void onSuccess(AnnotatedData<LeaderboardScore> leaderboardScoreAnnotatedData) {
if (leaderboardScoreAnnotatedData.get() == null)
mLeaderboardsClient.submitScore(leaderboardId, 1);
else {
long currentscore = leaderboardScoreAnnotatedData.get().getRawScore();
mLeaderboardsClient.submitScore(leaderboardId, currentscore + 1);
}
}
});
}