【问题标题】:Google Play Leaderboard serviceGoogle Play 排行榜服务
【发布时间】:2019-02-21 02:45:41
【问题描述】:
我想增加和减少我的分数
Games.getLeaderboardsClient(this, GoogleSignIn.getLastSignedInAccount(this))
.submitScore(getString(R.string.leaderboard_id), score);
使用这种方式只会增加我的分数
【问题讨论】:
标签:
android
google-play-games
leaderboard
【解决方案1】:
获取以前的分数:
Games.Leaderboards.loadCurrentPlayerLeaderboardScore(getApiClient(), getString(R.string.your_leaderboard_id), LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC).setResultCallback(new ResultCallback<Leaderboards.LoadPlayerScoreResult>() {
@Override
public void onResult(final Leaderboards.LoadPlayerScoreResult loadPlayerScoreResult) {
mPoints = loadPlayerScoreResult.getScore().getRawScore();
}
});
}
增加:
Games.Leaderboards.submitScore(gameHelper.getApiClient(), "LEADERBOARD_ID",loadPlayerScoreResult.getScore().getRawScore()+ score);
减少:
Games.Leaderboards.submitScore(gameHelper.getApiClient(), "LEADERBOARD_ID",loadPlayerScoreResult.getScore().getRawScore()- score);