Search code examples
objective-cuiviewcontrollersprite-kitsksceneskview

Displaying a Game Center Directly from a SKScene


I've been trying to display a game center leader board over an SKScene for awhile now and I can't figure it out I've looked at multiple articles.. From Google and Here when i click on the button that brings you to this scene it brings you there and displays a Grey Screen and that's it i have authenticated the player and everything. Is it possible that the view is behind the Scene? This is my Scene that I'm using

#import "DMLeaderBoard.h"
#import "DMGameKitHelper.h"


@implementation DMLeaderBoard


-(id)initWithSize:(CGSize)size {

    if (self = [super initWithSize:size]) {

        [self showLeaderboard];

    }
    return self;
}



-(void)showLeaderboard {

    GKGameCenterViewController *leaderboardController = [[GKGameCenterViewController alloc] init];
    if (leaderboardController != NULL)
    {
        leaderboardController.leaderboardIdentifier = @"1";
        leaderboardController.viewState = GKGameCenterViewControllerStateLeaderboards;
        leaderboardController.gameCenterDelegate = self;
        UIViewController *vc = self.view.window.rootViewController;
        [vc presentViewController: leaderboardController animated: YES completion:nil];
    }
}


- (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)viewController
{
    UIViewController *vc = self.view.window.rootViewController;
    [vc dismissViewControllerAnimated:YES completion:nil];
}

@end

Solution

  • Run the showLeaderboard method in didMoveToView because self.view is nil during init.