1

I'm having some issues. I have a cocos2d game I'm just about done developing. However I've run into a problem where I need to enable portrait orientation in my apps plist for game center sign in to work without throwing a SIGABRT error. So once I enable that from my app's build summary page (Or add it to the info.plist file as a supported orientation) it works fine. But then anytime in my game if you turn the iPhone it will flip to portrait mode if it senses you turned it that way. I've tried messing with the shouldAutorotateToInterfaceOrientation method from my AppDelegate.m and it's not getting called AT ALL, not at any time is it being called. I threw an NSLog statement in the method to be sure if it's being called, and it's not.

So, basically my real issue is. I need my game to STAY in landscape mode BESIDES when the Game Center login screen pops up. How do I do this in a Cocos2d 2.0 game?

I'm am using iOS6

Braydon Batungbacal
  • 1,028
  • 2
  • 24
  • 52

3 Answers3

3

First, make sure that the app supports portrait and landscape orientations in the target summary.

Then you'll need to make a new root view controller that forces you into landscape mode so that your game doesn't start rotating strangely:

@implementation CUSTOM_RootViewController
-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape;
}

- (BOOL)shouldAutorotate {
    return YES;
}

@end

Finally, in the AppDelegate.m file, replace the original navigation controller with your new one:

// Create a Navigation Controller with the Director
//navController_ = [[UINavigationController alloc] initWithRootViewController:director_];
navController_ = [[SMD_RootViewController alloc] initWithRootViewController:director_];
navController_.navigationBarHidden = YES;

Now you should be able to overlay a portrait view on top.

Hope this helps!

1

Use this code in AppDelegate.mm

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_6_0

-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape;
}

- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
    return UIInterfaceOrientationMaskLandscape;
}
#else
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
#endif
Guru
  • 21,652
  • 10
  • 63
  • 102
0

In IOs6 shouldAutorotateToInterfaceOrientation method not worked, so u change in appDelegate .m file [window addSubview:viewcontroller] to [window setRootviewcontroller:viewcontroller] after its works fine.