隐藏游戏场景后,前一个视图不可见

时间:2012-12-05 09:16:19

标签: iphone cocos2d-iphone ios6

我正在开发ios中的cocos2d游戏。 这是app delegate的代码:

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.homeViewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.window.rootViewController = self.homeViewController;
    [self.window makeKeyAndVisible];

在此我将ViewController课程设为rootViewController。 我将在GameOptionsViewController课程中提出HomeViewController课程。 从GameOptionsViewController我调用app delegate中的方法来添加游戏场景。

-(void)addGameScene

    {

    CCDirector *director = [CCDirector sharedDirector];
    if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
        [CCDirector setDirectorType:kCCDirectorTypeMainLoop];
    else {
        [CCDirector setDirectorType:kCCDirectorTypeDisplayLink];
    }

    // Init the View Controller
    viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
    viewController.wantsFullScreenLayout = YES;
    if(!glView)
        glView = [[EAGLView alloc] initWithFrame:[window bounds]];
    [director setOpenGLView:glView];

    [director setOpenGLView:glView];
    [director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
    [viewController setView:glView];
    [window setRootViewController:viewController];
    [window addSubview: viewController.view];
    [window makeKeyAndVisible];
    [[CCDirector sharedDirector] runWithScene: [HelloWorldLayer scene]];
}

现在,当我想隐藏游戏场景时,我使用代码:

   [[CCDirector sharedDirector] stopAnimation];
   [[CCDirector sharedDirector].openGLView setHidden:YES];

游戏场景被隐藏,但之前的视图,即GameOptionsViewController未显示。 我做错了什么?..请指教..

1 个答案:

答案 0 :(得分:1)

在这里你使用viewController设置RootViewController,就像那样..

[window setRootViewController:viewController];

因为它只是将你的GameOptionsViewController类对象设置为rootViewController ..

对于前。

   ViewController *homeViewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
   window.rootViewController = homeViewController;

我希望这可以帮助你...