Cocos 2d 2.0 shouldAutorotate not working?

I am having some problems. I have a cocos2d game, I'm just ready to develop. However, I ran into an issue where I need to enable portrait orientation in my game center login plist application in order to work without throwing a SIGABRT error. So as soon as I include this from my app build summary page (or add it to info.plist as a supported orientation) it works fine. But then, at any point in my game, if you turn on the iPhone, it will go into portrait mode if it feels like you've rotated it that way. I tried messing around with the toAutorotateToInterfaceOrientation method from my AppDelegate.m and it doesn't get the AT ALL call, but doesn't call it at all times. I threw an NSLog statement in the method to make sure it gets called and it isn't.

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

I am using iOS6

+1


source to share


3 answers


First, make sure the app supports portrait and landscape in the resulting PivotTable.

Then you will need to create a new root view controller that will force you into landscape mode so your game doesn't start spinning weird:

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

- (BOOL)shouldAutorotate {
    return YES;
}

@end

      

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



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

      

You can now overlay the portrait view on top.

Hope this helps!

+3


source


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

      

+1


source


In IOS6, the shouldAutorotateToInterfaceOrientation method didn't work, so change the [window addSubview: viewcontroller] file in appDelegate.m to [window setRootviewcontroller: viewcontroller] after it works fine.

0


source







All Articles