objective-cuiviewcocos2d-iphoneccscene

Cocos2d scene loaded with wrong orientation


I'm trying to make a cocos2d scene on top of some UIKit views. I understand that the cocos2d 2.0 CCDirector is a subclass of UIViewController so that I can just add that as a subview.

I've written this function to handle switching to a scene in my appDelegate (currently thats the delegate of my MainWindow.xib following http://www.raywenderlich.com/4817/how-to-integrate-cocos2d-and-uikit):

- (void)switchToScene
{
    self.viewController = [CCDirector sharedDirector];

    [[CCDirector sharedDirector] view].center = self.window.center;

    [self.window addSubview:[self.viewController view]];

    [[CCDirector sharedDirector] runWithScene:[CCTransitionSlideInL transitionWithDuration:1 scene:[BattleLayer scene]]];
}

So I'm missing quite a bit from this code. But with this, I get some resemblance of a scene to load https://i.sstatic.net/pubWE.png

My question is:

1: If I'm going in the right direction

2: If it is, is the next step to manually adjust the orientation of the scene?

2.1: How do I do this :)


Solution

  • I solved the issue by creating a UINavigationController

    - (void)switchToScene:(CCScene *)sceneObj
    {
        navController_ = [[UINavigationController alloc] initWithRootViewController:director_];
        [window_ setRootViewController:navController_];
        [[CCDirector sharedDirector] pushScene:sceneObj];
    }