I’m a beginner at cocos2d, and I’m trying to perform a segue from inside cocos2d.
Currently I set up the following function:
-(void) return_mm {
NSLog(@"returned to main menu");
UIViewController * con = self.controller;
[con performSegueWithIdentifier:@"Game2MenuSegue" sender:con];
}
to ran whenever a CCMenuItem is pressed. This actually does indeed work once. However, when I segue back into the game scene, the menu button stops working.
To be more specific, the segue is called, and the preparetosegue function is ran, but no transition happens. The other view’s viewWillAppear function never runs.
I’m probably doing something stupid, so if anyone has suggestions on doing this, it would be greatly appreciated.
This is what I currently have in the game view controller’s willDidAppear function.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if ([[CCDirector sharedDirector] isPaused]) {
[[CCDirector sharedDirector] resume];
[mainView addSubview:[[CCDirector sharedDirector] openGLView]];
return;
}
EAGLView *glview = [EAGLView viewWithFrame:self.view.bounds
pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8
depthFormat:0 // GL_DEPTH_COMPONENT16_OES
];
CCDirector *director = [CCDirector sharedDirector];
//[director setDisplayStats:kCCDirectorStatsFPS];
// Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
if( ! [director enableRetinaDisplay:YES] )
CCLOG(@"Retina Display Not supported");
[window makeKeyAndVisible];
[mainView addSubview:glview];
[director setOpenGLView:glview];
CCScene *scene = [CCScene node];
GameScene * gs =[GameScene sceneWithController:self];
[gs returnFromMenu];
[scene addChild:gs];
if (director.runningScene) {
[director replaceScene:scene];
} else {
[director runWithScene:scene];
}
}
I found the problem. I saved the controller on creation, but didn’t update it when it segues back into the game view. The controller was outdated so the segue didn’t do anything.
I just had to add
below the call to super