2

I'm trying to make a leaderboard for a game I created using SpriteBuilder. I have the following code.

if (gameCenterController != nil)
{
    gameCenterController.gameCenterDelegate = self;
    gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
    UIViewController *vc = self.view.window.rootViewController;
    [vc presentViewController: gameCenterController animated: YES completion:nil];
}

However, on the UIViewController *vc line, I keep getting the following error, "Property 'view' not found on object of type 'MainScene *'.

I have been searching for hours, does anyone know of a solution for this?

James Webster
  • 30,976
  • 11
  • 64
  • 113
Jude Michael Murphy
  • 1,184
  • 2
  • 11
  • 22

2 Answers2

3

MainScene does not have a view property because it isn't a UIViewController. There is only one UIViewController in a Cocos2d application and that is the CCDirector.

If you want to present a view controller you need to present it from the CCDirector:

 [[CCDirector sharedDirector] presentViewController:vc animated:YES completion:nil];
Ben-G
  • 4,896
  • 25
  • 33
0

I actually answered my own question! :D

UIViewController *vc = [[[[CCDirector sharedDirector] view] window] rootViewController];
Jude Michael Murphy
  • 1,184
  • 2
  • 11
  • 22