0

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

1 Answers1

1

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

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • Thank you so much :-) can i ask where you got that information for the documentation or did you just know? – user3466598 Aug 27 '14 at 14:21
  • It's not said explicitly but can be inferred. When you do [[Scene alloc] init..] the scene knows nothing of a view, it only gets assigned to a view when you do [skView presentScene:newScene] (for instance in the view controller). The same goes for nodes: [Node node] knows no self.scene during init, only after [self addChild:newNode] does the new node have a valid self.scene property. – CodeSmile Aug 27 '14 at 14:35