I have a normal storyboard in an iOS app. It contains ViewController “A” with a button. When that button is tapped, it loads a Cocos2D view – to do this I simply copied the code from the default AppDelegate that you get when you create a new Cocos2D project:
window_ = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
CCGLView *glView = [CCGLView viewWithFrame:[window_ bounds]
pixelFormat:kEAGLColorFormatRGB565
depthFormat:0
preserveBackbuffer:NO
sharegroup:nil
multiSampling:NO
numberOfSamples:0];
[glView setMultipleTouchEnabled:YES];
director_ = (CCDirectorIOS*) [CCDirector sharedDirector];
director_.wantsFullScreenLayout = YES;
[director_ setDisplayStats:YES];
[director_ setAnimationInterval:1.0/60];
[director_ setView:glView];
[director_ setDelegate:self];
[director_ setProjection:kCCDirectorProjection2D];
if( ! [director_ enableRetinaDisplay:YES] )
CCLOG(@"Retina Display Not supported");
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
[sharedFileUtils setEnableFallbackSuffixes:NO]; // Default: NO. No fallback suffixes are going to be used
[sharedFileUtils setiPhoneRetinaDisplaySuffix:@"-hd"]; // Default on iPhone RetinaDisplay is "-hd"
[sharedFileUtils setiPadSuffix:@"-ipad"]; // Default on iPad is "ipad"
[sharedFileUtils setiPadRetinaDisplaySuffix:@"-ipadhd"]; // Default on iPad RetinaDisplay is "-ipadhd"
[CCTexture2D PVRImagesHavePremultipliedAlpha:YES];
[director_ pushScene: [HelloWorldLayer scene]];
navController_ = [[UINavigationController alloc] initWithRootViewController:director_];
navController_.navigationBarHidden = YES;
[window_ setRootViewController:navController_];
[window_ makeKeyAndVisible];
That’s all very well, and it works like a charm when loading the “HelloWorldLayer”.
However I cannot seem to removed this “HelloWorldLayer” and make the app go back to using storyboards.
At the moment I have a function in my “HelloWorldLayer” that does the following:
[[CCDirector sharedDirector].openGLView removeFromSuperview];
[[CCDirector sharedDirector] removeFromParentViewController];
[self removeFromParentAndCleanup:TRUE];
This works well in literally removing the Cocos2D from the project, but I cannot tap anything in ViewController “A” after I have done the above: buttons do not respond to touches – it’s as if the app has frozen.
Help would be greatly appreciated!
PS: Here is a link to a file that has the problem: http://www.mediafire.com/?ipnlpinl5i0lw4a
OK, I figured it out: the
window_that is allocated in the first line of code is still covering ViewController A. I have to call[window_ release]from ViewController A once the HelloWorldLayer has visually disappeared to get it out of the way.