使用RoboVM和libgdx向GameCenter提交分数

时间:2017-09-21 05:10:02

标签: libgdx robovm game-center-leaderboard

我正在使用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,但它是客观的 - 所以我不明白答案。

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

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

}

任何人都知道问题可能是什么?我试过googleing但是关于“robovm和gamekit / gamecenter”的信息很少。

1 个答案:

答案 0 :(得分:1)

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