【问题标题】:Libgdx top score. Google play servicesLibgdx 最高分。谷歌播放服务
【发布时间】:2017-02-18 20:29:45
【问题描述】:

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

java.lang.IllegalStateException

在

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

【问题讨论】:

    标签: android libgdx google-play-services


    【解决方案1】:

    这样试试:

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

    【讨论】:

    • 感谢您的回复。显然我没有等待足够长的时间让我的排行榜开始正常工作。当我检查时,确实 arg0 是“null”。希望它对某些人有所帮助 - 等待一段时间,然后再使用排行榜并尝试向您的表格提交一些分数(似乎加快了流程并且排行榜开始响应)
    猜你喜欢
    • 2014-08-18
    • 2014-05-23
    • 1970-01-01
    • 1970-01-01
    • 2016-10-28
    • 2014-11-20
    • 2015-05-08
    • 1970-01-01
    相关资源
    最近更新 更多