Question

Every web page I read tells me to edit my "GameConfig.h" file. There is no such file in my project directory and if I try to import it I get an error. How can I change my default orientation without editing this illusive header file?

Was it helpful?

Solution

You didn't say which version of cocos2d you are using, but since you don't have a GameConfig.h file I'm going to guess you're using 2.0rc.

If that's the case, look in AppDelegate.m and you will find:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

Change Landscape to Portrait so you now have:

return UIInterfaceOrientationIsPortrait(interfaceOrientation);

Your game will then only autorotate between the two portrait orientations.

OTHER TIPS

In Cocos2D iPhone v3, you can set the orientation through the initial setup call, like so:

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self setupCocos2dWithOptions:@{
                                    CCSetupTabletScale2X: @(YES),
                                    CCSetupScreenOrientation: CCScreenOrientationPortrait
                                    }];
    return YES;
}

In Cocos2d v3 you have to set in your AppDelegate in the didFinishLaunchingWithOptions method as usual:

[self setupCocos2dWithOptions:@{
                                CCSetupShowDebugStats: @(YES),
                                CCSetupScreenOrientation: CCScreenOrientationPortrait,
    }];

(more options I've omitted are available)

and in the Info.plist of your project under the voice "Supported interface orientation" or "Supported interface orientation (iPad)" set Portrait instead of Landscape (which is default for iPads).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top