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?
kisg
(Gergely Kis - Migeran)
May 4, 2017, 8:33pm
2
Could you please provide us with a full, runnable test project that exhibits this issue?
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?
vighr
(Roland Vigh - Migeran)
May 19, 2017, 2:53pm
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
Okay I tried this just now @vighr , but still no leaderboard. No error or warning is shown either.
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!
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.
star_wint
(DoXuanHung)
May 26, 2017, 2:48am
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!
star_wint
(DoXuanHung)
May 26, 2017, 7:28am
10
Thank you very much!
I get a leaderboard successful!
star_wint
(DoXuanHung)
May 26, 2017, 8:02am
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.
Hi, you can use:
UIApplication.sharedApplication().openURL(NSURL.URLWithString(“gamecenter:”));
to trigger the GameCenter.
star_wint
(DoXuanHung)
June 12, 2017, 7:16am
13
thanks i will check that!