Game Center - Show a set of leaderboards

175 Views Asked by At

I just asked this question for Google Play Services, but I also have a Game Center implementation for iOS. My game has two modes - normal and hard. At the end of a game I would like to be able to show the leaderboards for the current mode instead of showing all the leaderboards - that would be a confusing mess. Is this possible with Game Center?

1

There are 1 best solutions below

0
On

As mentioned by @soulshined, you'll want to first check out the docs in the Game Center Programming Guide, specifically the section on Displaying the Standard Leaderboard. It'll explain this much better than short answers here will.

Basically though, you'll first create an instance of a GKGameCenterViewController, tell it that you want to display a leaderboard, then specify which leaderboard to display, and finally present the new view controller to the user. Like so (based on some tweaked sample code from Apple):

- (void) showLeaderboard: (NSString*) leaderboardID
{
    GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];
    if (gameCenterController != nil)
    {
       gameCenterController.gameCenterDelegate = self;
       gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
       gameCenterController.leaderboardIdentifier = leaderboardID;
       [self presentViewController: gameCenterController animated: YES completion:nil];
    }
}