Search code examples
iosios7uiviewcontrollercocos2d-iphonecocos2d-x

Page Navigation from a cocos2d scene to Uiviewcontroller


my project is a cocos2d game project, but i added a uiviewcontroller as loginview for the user. first scene in my project is logo showing scene,after that it will goes to the menu screen, but i need to pass to my uiviewcontroller(login) instead of menu screen,i tried lot of method but crashing.

-(id) init

{

if( (self=[super init] )) {
    CCSprite *sprBack = [CCSprite spriteWithFile:@"logo.png"];
    [sprBack setPosition:ccp(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2)];
    [self addChild:sprBack];

    [self schedule:@selector(logoTimer:) interval:3];
}

return self;

}

-(void) logoTimer: (ccTime) dt

{

[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:0.5f scene:[TitleLayer node ]  ]];

}

my uiviewcontroller name is loginviewcontroller.

i need to pass scene like this

 [[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:0.5f scene:[loginviewcontroller node ]  ]];

but showing error , i tired lot of method but unfortunalty nothing will gives me the correct solution .

one more thing loginviewcontroller is not node, its uiviewcontroller. i have tried this method also but it struck in the logo scene,no page transition taking place.

    -(void) logoTimer: (ccTime) dt{

    UIViewController *cocos = [[LogoViewController alloc] init];
    [cocos.navigationController dismissViewControllerAnimated:YES completion:nil];
 [cocos.navigationController popViewControllerAnimated:YES];



}

please help me.


Solution

  • Change and set the initial view controller to Login View Controller in didFinishLaunchingWithOptions and move setup of game engine in a newMethod in LoginViewController. The setup of game creates a new view controller which will open current Menu screen. On the event of successful credentials, call that newMethod and then push the view controller that is instantiated in game setup, and pop to go back to login.