2017-02-18 130 views
1

我用这个代码从排行榜最高分,但我不断收到Libgdx最高分。谷歌播放服务

java.lang.IllegalStateException

LeaderboardScore磅= arg0.getScores ()获得(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(); 
         } 
        }); 
     } 

回答

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

谢谢您的答复。显然,我没有等待足够长的时间让我的排行榜开始正常工作。当我检查时,arg0确实是“空”。希望对某些人会有所帮助 - 等待一段时间,然后再使用排行榜,并尝试向桌面提交一些分数(看起来加速进程和排行榜开始响应) –