Home Features Docs Blog Support GitHub

Libgdx: Leaderboard not displaying


(Chandu JR) #1

Hi,

I’m trying out intel-moe in my Libgdx project. I can sign into Game Center properly and Leaderboard is also seems to be working but it is not getting displayed.

IntelliJ Plugin: 1.3.1
moe SDK: 1.3.6
Libgdx: 1.9.6

This is my code where I call the leaderboard:

public void showLeaderBoard() {
    if(GKLocalPlayer.localPlayer().isAuthenticated() && !isLoadingLeaderboard) {
        GKLeaderboard.loadLeaderboardsWithCompletionHandler(new LeaderboardHandler());
        System.out.println("Querying leaderboard...");
    }
}

And this is the LeaderboardHandler class:

private class LeaderboardHandler implements GKLeaderboard.Block_loadLeaderboardsWithCompletionHandler {
    @Override
    public void call_loadLeaderboardsWithCompletionHandler(NSArray<? extends GKLeaderboard> leaderboards, NSError nsError) {
        isLoadingLeaderboard = true;
        if (nsError != null) {
            System.out.println(String.format("Error on loading leaderboards: %s", nsError.toString()));
        }

        if (leaderboards != null && leaderboards.size() > 0) {
            leaderboards.get(0).setPlayerScope(GKLeaderboardPlayerScope.Global);
            leaderboards.get(0).setTimeScope(GKLeaderboardTimeScope.AllTime);
            leaderboards.get(0).loadScoresWithCompletionHandler(new GKLeaderboard.Block_loadScoresWithCompletionHandler() {
                @Override
                public void call_loadScoresWithCompletionHandler(NSArray<? extends GKScore> scores, NSError nsError) {
                    System.out.println("Got leaderboard");
                }
            });
        }
    }
}

Here, call_loadScoresWithCompletionHandler is getting called successfully because I get “Got leaderboard” in the console. But no leaderboard screen is displayed. I can touch UI elements in my app screen as well, so nothing transparent is overlaying. May somebody help me find a solution to this?


(Gergely Kis - Migeran) #2

Could you please provide us with a full, runnable test project that exhibits this issue?


(Chandu JR) #3

Hey @kisg sorry I didn’t see this message before. I’ll try to submit a fresh project. Meanwhile, can you see any error in this code where I’m calling the leaderboard view? I’m pretty sure the error is in here:

@Override
public void showLeaderBoard() {
    if(GKLocalPlayer.localPlayer().isAuthenticated()) {
        GKLeaderboard.loadLeaderboardsWithCompletionHandler(new GKLeaderboard.Block_loadLeaderboardsWithCompletionHandler() {
            @Override
            public void call_loadLeaderboardsWithCompletionHandler(NSArray<? extends GKLeaderboard> leaderboards, NSError nsError) {
                if (nsError != null) {
                    System.out.println(String.format("Error on loading leaderboards: %s", nsError.toString()));
                }
                if (leaderboards != null && leaderboards.size() > 0) {
                    leaderboards.get(0).setPlayerScope(GKLeaderboardPlayerScope.Global);
                    leaderboards.get(0).setTimeScope(GKLeaderboardTimeScope.AllTime);

                    leaderboards.get(0).loadScoresWithCompletionHandler(new GKLeaderboard.Block_loadScoresWithCompletionHandler() {
                        @Override
                        public void call_loadScoresWithCompletionHandler(NSArray<? extends GKScore> scores, NSError nsError) {
                            System.out.println("Got leaderboard scores");

                            GKGameCenterViewController gameCenterViewController = GKGameCenterViewController.alloc();
                            gameCenterViewController.init();
                            gameCenterViewController.setViewState(GKGameCenterViewControllerState.Leaderboards);
                            gameCenterViewController.setLeaderboardIdentifier(leaderboards.get(0).identifier());

                            gameCenterViewController.setGameCenterDelegate(new GKGameCenterControllerDelegate() {
                                @Override
                                public void gameCenterViewControllerDidFinish(GKGameCenterViewController gameCenterViewController) {
                                    gameCenterViewController.dismissViewControllerAnimatedCompletion(true, null);
                                }
                            });

                            window().rootViewController().presentViewControllerAnimatedCompletion(gameCenterViewController, true, null);
                        }
                    });
                }
            }
        });
    }
}

Last time I didn’t do anything in the call_loadScoresWithCompletionHandler method, that’s why nothing was displayed (duh!) except “Got leaderboard scores”. But now even after calling presentViewControllerAnimatedCompletion method, leaderboard is not showing up.

Is it not the right way to display a view?


(Roland Vigh - Migeran) #4

Hi!

Please try this code:

...
@Override
protected IOSApplication createApplication() {
...
application = new IOSApplication(new MyGdxGame(), config);
...

@Override
public void showLeaderBoard() {

...

application.getUIWindow().rootViewController()
                                    .presentViewControllerAnimatedCompletion
                                    (gameCenterViewController, true, null);

...

Best Regards,
Roland


(Chandu JR) #5

Okay I tried this just now @vighr, but still no leaderboard. No error or warning is shown either.


(Chandu JR) #6

Weird thing! If I put a breakpoint at

application.getUIWindow()
.rootViewController()
.presentViewControllerAnimatedCompletion(gameCenterViewController, true, null);

and debug, then the leaderboard will appear when I resume!


(Chandu JR) #7

I think this is because I run in a simulator. The leaderboard appears sometimes when run normally. I haven’t tried on a device yet.


(DoXuanHung) #8

Hi Chandu JR!

How to add leaderboard in IOS? I’m newbie in MOE and IOS too, I find full guideline or example project but don’t have. Can you share full guideline/example project for that? Very thanks!


(Chandu JR) #9

Check out this tutorial:

https://reimerm.de/2016/11/integrating-gamecenter-into-libgdx-java-multi-os-engine-8/

That’s where I started.


(DoXuanHung) #10

Thank you very much!
I get a leaderboard successful!


(DoXuanHung) #11

I have a question?

How to show GameCenter login again if user dismisses login screen before? I have a button, and call login GameCenter, the first login screen show ok, i cancel login and click again. Nothings show.


(Ram52 Studio) #12

Hi, you can use:
UIApplication.sharedApplication().openURL(NSURL.URLWithString(“gamecenter:”));
to trigger the GameCenter.


(DoXuanHung) #13

thanks i will check that!