1

OK, so I'm trying to show Apple Game Center Leaderboards called from within my cocos2d game.

I've had some trouble doing so.

I did eventually stumble upon this and I implemented the following in one of my CCScene classes (I slightly modified the original code to prevent a compiler warning).

- (void)showLeaderboardForCategory:(NSString *)category
{
    // Create leaderboard view with default Game Center style
    leaderboardController = [[GKLeaderboardViewController alloc] init];

    // If view controller was successfully created...
    if (leaderboardController != nil)
    {
        // Leaderboard config
        leaderboardController.leaderboardDelegate = self; // leaderboardController will send messages to this object
        leaderboardController.category = category;
        leaderboardController.timeScope = GKLeaderboardTimeScopeAllTime;

        // Create an additional UIViewController to attach the GKLeaderboardViewController to
        vc = [[UIViewController alloc] init];

        // Add the temporary UIViewController to the main view
        [[CCDirector sharedDirector].view.window addSubview:vc.view];

        // Tell UIViewController to present the leaderboard
        [vc presentModalViewController:leaderboardController animated:YES];
    }
}

- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
    [vc dismissViewControllerAnimated:YES completion:nil];
}

And, it works! At least when I call it, it does display the Leaderboard properly.

The only problem is, when I tap "Done" on the Leaderboard and the modal view dismisses, my CCScene no longer responds to tap events.

What do I need to do to regain responsiveness?

4

1 回答 1

1

参考示例普通 cocos2d 项目:

     -(void)showLeaderboard
      {
        GKLeaderboardViewController *leaderboardViewController = [[GKLeaderboardViewController alloc] init];
        leaderboardViewController.leaderboardDelegate = self;
        AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
        [[app navController] presentModalViewController:leaderboardViewController animated:YES];
        [leaderboardViewController release];
     }

代理功能:

-(void) leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
    AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
    [[app navController] dismissModalViewControllerAnimated:YES];
}
于 2013-03-06T06:23:16.567 回答