cocos2d-iphoneuinavigationcontrollersceneadobe-director

UINavigationController with PKRevealController's SideBar and cocos2d, not showing first scene


I'm using PKRevealController to show a SideBar, so in the AppDelegate I've this to set the UINavigationController and my ViewControllers:

FirstViewController *firstController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];

UINavigationController *menuViewController = [[UINavigationController alloc] initWithRootViewController:firstController];

UIViewController *sideViewController = [[SideViewController alloc] init];

self.revealController = [PKRevealController revealControllerWithFrontViewController:menuViewController leftViewController:sideViewController options:nil];

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

this is working, and the firstViewController is is showing with the side bar (the sideViewController)

but now I need to setup the cocos2d scene, and usually you need to setup the navController, here is where probably I'm a little bit confused, and there's what I'm trying to do:

CCGLView *glView = [CCGLView viewWithFrame:[window_ bounds]
                                   pixelFormat:kEAGLColorFormatRGB565
                                   depthFormat:0
                            preserveBackbuffer:NO
                                    sharegroup:nil
                                 multiSampling:NO
                               numberOfSamples:0];

director_ = (CCDirectorIOS*) [CCDirector sharedDirector];

navController_ = [[MyNavigationController alloc] initWithRootViewController:self.revealController];
    navController_.navigationBarHidden = YES;

[window_ setRootViewController:navController_];

[self.window makeKeyAndVisible];

and the method directorDiDReshapeProjection is not even being called !

-(void) directorDidReshapeProjection:(CCDirector*)director
{
    NSLog(@"called");
        if(director.runningScene == nil) {
            NSLog(@"if statement called");
            [director runWithScene: [IntroLayer scene]];
    }
}

I'm calling the method with a button basically, with the transitionFromViewController:toViewController: method

[self transitionFromViewController::firstController toViewController:[CCDirector sharedDirector] duration:1.0 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
    }  completion:^(BOOL finished){if (finished) {
        firstController=[CCDirector sharedDirector];
    }}];

the transition is going, but the "other side" is a black scene. And, as I said, the directorDidReshapeProjection method is NOT called :\

I'm using this method in other games btw, and they're working, only here I've used PKRevealController which is using a UINavigationController and my approach is not working

can someone explain to me why? what I'm doing wrong with the UINavigationControllers? (I'm pretty sure that's the problem)


Solution

  • Solved ! two things:

    1. I needed to add the [director_ setDelegate:navController_] (I've not noticed his absence before) and that's why my directorDidReshapeProjection method wasn't called.

    2. I've added a "general" view controller where to show the PKRevealController and then switch with the cocos2d scene, so first in the application: didFinishLaunchingWithOptions: method I alloc the generalViewController, then I setup the glView, set the director, and before to set the navController I create the PKRevealController and set the frontViewController and leftViewController (in my case I have these two).

    After that I do:

    navController_ = [[MyNavigationController alloc] initWithRootViewController:self.revealController];
    
    [director_ setDelegate:navController_]
    [window_ setRootViewController:navController_];
    

    and now is working without error messages, hope this help someone