0
votes

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 http://i.stack.imgur.com/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 :)

2

2 Answers

0
votes

I'm not sure how you want it to look but it seems that the CCDirector's view is rotated 90 degrees CW. This may be because of a few reasons:

  1. you add the view wrong (i.e. rotated 90 degrees CW)
  2. you rotated the device and the CCDirector didn't rotate (in which case you should look at orientation parameters and who and what rotates. It may be that the app rotates but CCDirector doesn't receive the rotation flag).
  3. you can rotate the CCDirector view with CGAffineTransformRotate (i'm not sure..but because CCDirector is a subclass of UIViewController..it should work).
0
votes

I solved the issue by creating a UINavigationController

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