0
votes

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];
    }
}
1
This will create a new glView every time the view appears. That's going to be a problem. You want to setup cocos2d in applicationDidFinishLaunching and afterwards only pause/resume (stop/startAnimation) the director. - LearnCocos2D
Ahh okay, gotcha. I think it's actually not recreating the glView though, because the transition pauses the director, and it will resume and return before it recreates the view - Xzhsh

1 Answers

0
votes

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

gs.controller = self

below the call to super