Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 784
chelo_c Avatar asked Aug 07 '13 23:08

chelo_c


1 Answers

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.

like image 91
chelo_c Avatar answered Oct 31 '22 18:10

chelo_c