Game Center login portrait only any solution for Kobold2d

220 Views Asked by At

I am a beginner using Kobold2d v2.0.4, My games that I am creating is target for only iOS 6 and was design to run on Landscape orientation only, and when I implemented game center I found that game center login on iOS 6 only run on portrait, so I search and found the solution but the problem is I couldn't find where to put them in Kobold2d. Add this to your RootViewController

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

-(BOOL)shouldAutorotate {
    return [[UIDevice currentDevice] orientation] != UIInterfaceOrientationPortrait;
}

I had try look for KKRootViewController but I could find, I just wondering how the other Kobold2d developer find the solution to solve this problem. If you wouldn't mind could you please advise me on how you resolve it. Thank you kindly.

2

There are 2 best solutions below

1
On BEST ANSWER

I haven't tested it myself, I think it might work if you put this code in your project's AppDelegate class. If not, you may have to create a category with these methods, either on KKRootViewController or CCDirector.

0
On

What actually worked for me is selecting portrait and both landscape orientations in app summary, then creating a category on UINavigationController, since Kobold2D uses a navigation controller as rootViewController on the window.

@implementation UINavigationController (GameCenter)

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

-(BOOL)shouldAutorotate {
    return [[UIDevice currentDevice] orientation] != UIInterfaceOrientationPortrait;
}

@end

And importing it to AppDelegate.m file. Thanks for the idea anyways...