Google Play排行榜服务

时间:2018-09-17 08:06:09

标签: android google-play-games leaderboard

我想增加和减少分数

    Games.getLeaderboardsClient(this, GoogleSignIn.getLastSignedInAccount(this))
            .submitScore(getString(R.string.leaderboard_id), score); 

使用这种方式只会增加我的分数

1 个答案:

答案 0 :(得分:0)

要获取以前的分数:

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);