Android Game API: Leaderboard - Get specific player score? [closed]

邮差的信 提交于 2019-12-04 12:01:56

问题


SOLVED

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.

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?

Thanks!


回答1:


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

On your activity:

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

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.

Cheers.



来源:https://stackoverflow.com/questions/18115615/android-game-api-leaderboard-get-specific-player-score

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!