安卓游戏API:排行榜 - 获取特定玩家的分数?分数、排行榜、玩家、游戏

2023-09-05 06:22:55 作者:炙热是你

解决

我有一个快速的问题,我无法找到一个具体的解决方案。 问题是,我使用GooglePlay API一个排行榜。 我想要做的就是真正得到了什么是玩家分数为个人和特殊的球员。

I have a quick question that I cant find a specific solution. The problem is that I have a Leaderboard using GooglePlay API. What I want to do is actually get what is the player score for an individual and specific player.

例如我要显示在我的活动(不LeaderboardActivity)上的绳子,他有得分的排行榜,还是把它放在我的游戏的左上角。

For example I want to display the score he has in the leaderboard on a String on my activity (not LeaderboardActivity), or put it on top left corner of my game.

我怎样才能做到这一点?

How can I do this?

谢谢!

推荐答案

不知道为什么downvotes .. 反正这里是我发现了解决这个问题的方法:

Dont know why the downvotes.. Anyways here is the way I found to solve this:

在你的活动:

if (isSignedIn()) {
    getGamesClient().loadPlayerCenteredScores(
        this,
        getResources().getString(R.string.leaderboard_id),
        LeaderboardVariant.TIME_SPAN_ALL_TIME,
        LeaderboardVariant.COLLECTION_SOCIAL,
        25,
        true
    );
}

然后在监听器:

then on the listener:

@Override
public void onLeaderboardScoresLoaded(int arg0, LeaderboardBuffer arg1, LeaderboardScoreBuffer arg2) {
    Iterator<LeaderboardScore> it = arg2.iterator();
    while(it.hasNext()) {
         LeaderboardScore temp = it.next();
         Log.d("debug", "player:" + temp.getScoreHolderDisplayName() + " id:" + temp.getScoreHolder().getPlayerId());
    }
}

这名球员是中锋得分,所以如果你把甚至导致玩家应该是在中间。您可以循环,并检查玩家的ID相符。

The player is the center score so if you bring even results the player should be in the middle. You can iterate and check if the player id matches.

干杯。