我读到leaderboards在谷歌所有文件播放服务,似乎当我打电话GameClient的submitScore函数只提交分数最高的服务考虑。例如。:
第一个呼叫:
gamesclient.submitScore( 100 );
现在球员得分100
第二个呼叫:
gamesclient.submitScore( 150 );
现在,玩家的分数为150
第三个呼叫:
gamesclient.submitScore( 100 );
球员得分仍然150提交的值是否因此将其忽略,比去年不大于。
有一个简单的方法来检索最后的球员得分,总结新的成绩,并提交总的创建增量得分排行榜中?就像是
int old_score = ...GET LAST PLAYER SCORE...
int new_score = old_score + current_game_score;
gamesclient.submitScore( new_score );
没有测试,到目前为止,但我认为是要走的路:
PendingResult<Leaderboards.LoadPlayerScoreResult> result = Games.Leaderboards.loadCurrentPlayerLeaderboardScore(gameHelper.getApiClient(),"LEADERBOARD_ID",LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC);
result.setResultCallback(new ResultCallback<Leaderboards.LoadPlayerScoreResult>() {
@Override
public void onResult(Leaderboards.LoadPlayerScoreResult loadPlayerScoreResult) {
Games.Leaderboards.submitScore(gameHelper.getApiClient(), "LEADERBOARD_ID",loadPlayerScoreResult.getScore().getRawScore()+ score);
}
似乎并不喜欢有不幸的是这样做的内置方式。但是,你可以使用Cloud Save只保存最近的玩家的分数,只是使用它。
另外,(这似乎有点俗气),每次提交积分时间,节省SharedPreferences
该分数,然后当你提交接连得分,使用偏好来增加分数,而不是建立一个全新的一个。
但愿这是有帮助,如果这是不是真的,你想如何去解决您的问题,让我知道,我会尽力找到另一个解决方案...
以下是我想出了...
@Override
public void postNewScore(final int finalScore, final ArrayList<String> theseBoards) {
//posts score update to any theseBoards... most likely 2 boards
for (final String anID : theseBoards) {
aHelper.getGamesClient().loadPlayerCenteredScores(new OnLeaderboardScoresLoadedListener() {
@Override
public void onLeaderboardScoresLoaded(int statusCode, Leaderboard leaderboard, LeaderboardScoreBuffer scores) {
if(statusCode == GamesClient.STATUS_OK){
if(scores.getCount() == 0){
aHelper.getGamesClient().submitScore(anID, finalScore);
dLog("submitted a score because there were no scores period");
} else {
for (LeaderboardScore s : scores) {
if(s.getScoreHolder().getPlayerId().contains(aHelper.getGamesClient().getCurrentPlayer().getPlayerId()) ||
aHelper.getGamesClient().getCurrentPlayer().getPlayerId().contains(s.getScoreHolder().getPlayerId())){
aHelper.getGamesClient().submitScore(anID, finalScore + s.getRawScore());
dLog("just submitted " + (finalScore + s.getRawScore()));
scores.close();
return;
}
}
//if to here, then no score on the current page, which means the player does not have a score
aHelper.getGamesClient().submitScore(anID, finalScore);
dLog("because no entry, just submitted " + (finalScore));
}
}
scores.close();
}
}, anID, LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_SOCIAL, 1);
}
}
虽然你已经给出了如何增加分数的例子,你不能使用排行榜的排名表,其中得分下降。
谷歌目前只允许设施隐藏涉嫌作弊的分数。如果有一些方法来降低分数或删除它们完全你就可以做你的要求。
我想,这背后的原因是,如果他们让你修改已经公布的分数会降低用户的信任,无论是谷歌Play游戏服务平台,藏汉作为你的游戏 - 歪曲什么玩家喜欢采取的所有权(原谅的行话。) 。
这导致比分通胀随着时间的推移,我认为他们使用的64个整数内部:
/**
* Submit a score to the leaderboard for the currently signed-in player.
* The score is ignored if it is worse (as defined by the leaderboard
* configuration) than a previously submitted score for the same player.
*/
void SubmitScore(std::string const &leaderboard_id, uint64_t score);
但是,您可以修改排行榜的固定营业场所的小数位点位置作为一门课程调整到这个通货膨胀。我不会。
很抱歉,如果这是题外话,让我们希望谷歌考虑到这一点在未来的更新。
如果有人还在寻找解决方案,根据最新的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);
}
}
});
}