Libgdx最高分。谷歌播放服务

时间:2017-02-18 20:29:46

标签: android libgdx google-play-services

我使用此代码从排行榜获得最高分,但我一直在

  

java.lang.IllegalStateException

at

  

LeaderboardScore lbs = arg0.getScores()。get(0);

我不知道出了什么问题。它在我之前的项目中起作用

public void updateTops() {
            Games.Leaderboards.loadTopScores(client, getString(R.string.leaderboard_score),
                    LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC, 2, true).
                    setResultCallback(new ResultCallback<Leaderboards.LoadScoresResult>() {
                        @Override
                        public void onResult(final Leaderboards.LoadScoresResult arg0) {
                            System.out.println("SUKA " + score);
                            LeaderboardScore lbs = arg0.getScores().get(0);
                            score = lbs.getDisplayScore();
                            name = lbs.getScoreHolderDisplayName();
                            arg0.getScores().close();
                        }
                    });
        }

1 个答案:

答案 0 :(得分:2)

尝试这种方式:

 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) {

            if(arg0 != null) {
                 if (arg0.getStatus().getStatusCode() == GamesStatusCodes.STATUS_OK) {

                   int size = arg0.getScores().getCount();
                   LeaderboardScoreBuffer scoreBuffer = arg0.getScores();
                   Iterator<LeaderboardScore> it = scoreBuffer.iterator();
                   while(it.hasNext()){
                        LeaderboardScore temp = it.next();
                        Log.d("PlayGames", "player"+temp.getScoreHolderDisplayName()+" score:"+temp.getDisplayScore());
                   }
                }
            }
  }