Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My app is designed to use Cocos2D in the "main game screen" but the rest of the screens are in UIKit. While I feel that this isn't ideal, I really don't have time to port the rest of the screens into Cocos2D for the time being.

One of the problems I face is that I am required to load all the textures each time I enter the main game screen, and discard them once I leave Cocos2D-land (and repeat the process all over again)... or am I?

I am actually wondering if I could preload all the textures needed in a CCTextureCache during startup, even when the EAGLView and context hasn't yet been set up until I visit the main screen (and in doing so preserve the texture cache contents). But whenever I try this the app crashes.

Any way in which I can do this?

share|improve this question
up vote 0 down vote accepted

How are you implementing mixing UIKit with Cocos2D?

The approach I use is to create a UINavigationController in the application didFinishLaunching... method and add the Cocos2D director as its root view controller.

navigator = [[UINavigationController alloc] initWithRootViewController:director];
[navigator setNavigationBarHidden:YES];

This way, using standard methods on the navigation controller, you can freely swap between UIKit view controllers and whatever Cocos2D is displaying without fully "shutting down" Cocos2D and flushing all its resources.

share|improve this answer
How would that work if I had to show a regular UIViewController subclass at startup? What I had done was to push into another UIViewController, one of whose views had to call this on itself: [[CCDirector sharedDirector] setOpenGLView:self]. – Aldrich Co Feb 12 '13 at 3:05
Add the other view controller with initWithRootViewController, then use [navigationController pushViewController:[CCDirector sharedDirector] animated:NO] to display your Cocos2D scenes, and [navigationController popViewControllerAnimated:YES] to return to UIKit. – nivrig Feb 12 '13 at 8:55
For reference, UINavigationController documentation. – nivrig Feb 12 '13 at 8:57
I finally got it to work! Since I have a UIViewController subclass that owns the EAGLView, I kept that UIViewController instance around and then switched to it when I have to go into Cocos2D-land. But your code example would have errors in it. You can't pass a Cocos2d director to initWithRootViewController:. – Aldrich Co Feb 12 '13 at 10:56
CCDirector extends UIViewController on iOS in 2.x - I think this changed from 1.x. – nivrig Feb 12 '13 at 11:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.