2017-02-18 126 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確實是「空」。希望對某些人會有所幫助 - 等待一段時間,然後再使用排行榜,並嘗試向桌面提交一些分數(看起來加速進程和排行榜開始響應) –