我正在开发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
未显示。
我做错了什么?..请指教..
答案 0 :(得分:1)
在这里你使用viewController设置RootViewController,就像那样..
[window setRootViewController:viewController];
因为它只是将你的GameOptionsViewController
类对象设置为rootViewController ..
对于前。
ViewController *homeViewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
window.rootViewController = homeViewController;
我希望这可以帮助你...