【问题标题】:Submitting score to GameCenter using RoboVM and libgdx使用 RoboVM 和 libgdx 向 GameCenter 提交分数
【发布时间】:2017-09-21 05:10:02
【问题描述】:

我正在使用 libgdx 和 robovm。

当我尝试在 iOS 上的 GameCenter 上将分数提交到排行榜时出现错误。我能够显示排行榜。这是我得到的错误:

*** Terminating app due to uncaught exception 'GKInvalidArgumentException', reason: 'A GKScore must specify a leaderboard.' libc++abi.dylib: terminating with uncaught exception of type NSException

和这个SO-post类似,但是是objective-c所以没看懂答案。

这是我显示排行榜的代码(可行)

public void getLeaderboardGPGS() {

    // If player is not authenticated, do nothing
    if (!GKLocalPlayer.getLocalPlayer().isAuthenticated()) {
        return;
    } 
    GKGameCenterViewController gameCenterView = new GKGameCenterViewController();

    gameCenterView.setGameCenterDelegate(new GKGameCenterControllerDelegateAdapter() {
        @Override
        public void didFinish (GKGameCenterViewController gameCenterViewController) {
            dismissViewControllerAndNotifyListener(gameCenterViewController, GKGameCenterViewControllerState.Leaderboards);
        }
    });
    gameCenterView.setViewState(GKGameCenterViewControllerState.Leaderboards);

    gameCenterView.setLeaderboardIdentifier(identifier);


    keyWindow.getRootViewController().presentViewController(gameCenterView, true, null);
}

这是我提交分数的代码(这不起作用)

public void submitScoreGPGS(int score, MyLeaderBoardCallback callback) {

    // If player is not authenticated, do nothing
    if (!GKLocalPlayer.getLocalPlayer().isAuthenticated()) {
        //listener.scoreReportFailed(buildUnauthenticatedPlayerError());
        Gdx.app.log("Gamecenter","Notlogedin");
        return;
    }
    GKScore scoreReporter = new GKScore(identifier);

    scoreReporter.setValue(score);
    scoreReporter.setLeaderboardIdentifier(identifier);
    //scoreReporter.setShouldSetDefaultLeaderboard(true);
    //scoreReporter.setContext(0);

    NSArray<GKScore> scores = new NSArray<GKScore>(scoreReporter);

    Gdx.app.log("Gamecenter","Report socre");
    GKScore.reportScores(scores, new VoidBlock1<NSError>() {
        @Override
        public void invoke (NSError error) {
            if (error != null) {
                Gdx.app.log("Gamecenter","scorereportfailed");
            } else {
                Gdx.app.log("Gamecenter","scorereportcompleted");
            }
        }
    });

}

有人知道问题可能是什么吗?我试过用谷歌搜索,但关于“robovm 和 gamekit/gamecenter”的信息很少。

【问题讨论】:

    标签: libgdx robovm game-center-leaderboard


    【解决方案1】:

    包含排行榜 ID 的变量因某种原因被垃圾回收。必须在 scoreReporter.setLeaderboardIdentifier("my hard coded id"); 处对字符串进行硬编码。奇怪....

    【讨论】:

      猜你喜欢
      • 2012-05-03
      • 1970-01-01
      • 2014-03-13
      • 1970-01-01
      • 2023-03-30
      • 2019-09-13
      • 1970-01-01
      • 1970-01-01
      • 2014-08-07
      相关资源
      最近更新 更多