Preserving Cocos2D context between UIKit screens

| | August 6, 2015

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?

One Response to “Preserving Cocos2D context between UIKit screens”

  1. 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.

Leave a Reply