Search code examples
kobold2dappdelegate

How to use AppDelegate alternateView in Kobold2D to replace rootViewController


I want to create a Kobold2D app with a container view that will hold both the cocos2d CCDirector view and my own UIViews. I can see from documentation that this can be done using the alternateView method in the AppDelegate but I can't see how to use this method and what exactly it should return. Could you provide me with an example?


Solution

  • It should simply return a UIView. The "Cocos2D with UIKit Views" template project uses the alternateView method to create exactly this kind of container view:

    @implementation AppDelegate
    
    -(id) alternateView
    {
        // we want to be a dummy view the self.view to which we add the glView plus all other UIKit views
        KKAppDelegate* appDelegate = (KKAppDelegate*)[UIApplication sharedApplication].delegate;
    
        // add a dummy UIView to the view controller, which in turn will have the glView and later other UIKit views added to it
        CGRect bounds = [appDelegate.window bounds];
        UIView* dummyView = [[UIView alloc] initWithFrame:bounds];
        [dummyView addSubview:[CCDirector sharedDirector].view];
    
        return dummyView;
    }
    
    @end
    

    This code goes in your project's AppDelegate.m