Top 5 points from google leaderboard

My requirement is to get the 5 best points from the leaderboard and display them in my application.

There is a loadTopScores method, but it shows the scores in the native UI, I think.

mGamesClint.loadTopScores(new OnLeaderboardScoresLoadedListener() {

            public void onLeaderboardScoresLoaded(int arg0, LeaderboardBuffer arg1,
                    LeaderboardScoreBuffer arg2) {
                // TODO Auto-generated method stub




            }
        }, LEADERBOARD_ID,LeaderboardVariant.TIME_SPAN_ALL_TIME  , LeaderboardVariant.COLLECTION_PUBLIC, 5, true);

So is there a way to get individual data like Name and score.?

Title 1: Name of the best scorer 1 rating 1: rating of the best scorer 1

Title 2: Name of the best scorer 2 rating 2: rating of the best scorer 2

...... etc.

I just need a name string and an integer so that I can use it in my game.

Please suggest me some ideas.

+4
source share
3 answers

, , : .

  Games.Leaderboards.loadTopScores(mGamesClint,LEADERBOARD_ID, LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC, 5).setResultCallback(new ResultCallback<Leaderboards.LoadScoresResult>() {

        public void onResult(LoadScoresResult arg0) {
            // TODO Auto-generated method stub

            int size = arg0.getScores().getCount();



            for ( int i = 0; i < 3; i++ )  {

                LeaderboardScore lbs = arg0.getScores().get(i);

                String name = lbs.getScoreHolderDisplayName();

                String score = lbs.getDisplayScore();

                Uri urlimage = lbs.getScoreHolderHiResImageUri();

                 }

 }

, , .. . , .

+2

, . , , , , - , , , , , .

, arg2, , :

mGamesClint.loadTopScores(new OnLeaderboardScoresLoadedListener() {

   public void onLeaderboardScoresLoaded(int arg0, LeaderboardBuffer arg1, LeaderboardScoreBuffer arg2) {

      // iterate through the list of returned scores for the leaderboard
      int size = arg2.getCount();
      for ( int i = 0; i < size; i++ )  {
         LeaderboardScore lbs = arg2.get( i );

         // access the leaderboard data
         int rank = i + 1;         // Rank/Position (#1..#2...#n)
         String name = lbs.getScoreHolderDisplayName();
         String scoreStr = lbs.getDisplayScore();
         long score = lbs.getRawScore();

         // now display or cache these values, or do whatever with them :)
      }

      arg2.close();
      arg1.close();
   }
}, LEADERBOARD_ID,LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC, 5, true);

, (, , , , ).

, , , .

+3

.

PendingResult<Leaderboards.LoadScoresResult> topScores = 
            Games.Leaderboards.loadTopScores(getApiClient(),LEADERBOARD_ID,LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC, 1, true);
            topScores.setResultCallback(new ResultCallback<Leaderboards.LoadScoresResult>() {

                @Override
                public void onResult(LoadScoresResult scoreResults) {

                    if(scoreResults != null) {
                        if (scoreResults.getStatus().getStatusCode() == GamesStatusCodes.STATUS_OK) {
                            scoreStringBuilder = new StringBuilder();
                            LeaderboardScoreBuffer scoreBuffer = scoreResults.getScores();
                            Iterator<LeaderboardScore> it = scoreBuffer.iterator();
                            while(it.hasNext()){
                                 LeaderboardScore temp = it.next();
                                 Log.d("PlayGames", "player"+temp.getScoreHolderDisplayName()+" id:"+temp.getRawScore() + " Rank: "+temp.getRank());
                                 scoreStringBuilder.append("|"+temp.getScoreHolderDisplayName()+"*"+temp.getRawScore());
                            }
                            UnityPlayer.UnitySendMessage(handlerName, "onGetScoreSucceededEventListener", "");
                             Log.d("PlayGames", "Call Sent for getHighScorewithPlayerNameSuccess ::: "+handlerName);


                        }
                    }

                }});

, , Unity, . Google Play.

+3
source

Source: https://habr.com/ru/post/1543388/


All Articles