Nick
Nick

Reputation: 111

Cocos2d portrait mode not working on iPhone

I'm building a cocos2d game which is supposed to be in portrait mode. I changed the RootViewController.m to portrait mode, and everything works fine, both on the simulator and on my iPad. However, when I run the game on my iPhone, it defaults back to landscape mode.

Any ideas on how to fix this?

Thanks.

Upvotes: 5

Views: 3329

Answers (5)

akc
akc

Reputation: 582

in GameConfig.h:

For 1st and 2nd generation devices, value is set to kGameAutorotationNone, change it to kGameAutorotationUIViewController.

// ARMv6 (1st and 2nd generation devices): Don't rotate. It is very expensive
#elif __arm__
#define GAME_AUTOROTATION kGameAutorotationNone

Upvotes: 0

Aurelien Cobb
Aurelien Cobb

Reputation: 435

in GameConfig.h:

use the director for autorotation

#if defined(__ARM_NEON__) || TARGET_IPHONE_SIMULATOR
#define GAME_AUTOROTATION kGameAutorotationCCDirector 

instead of

#if defined(__ARM_NEON__) || TARGET_IPHONE_SIMULATOR
#define GAME_AUTOROTATION kGameAutorotationUIViewController

and in the AppDelegate.m

- (void) applicationDidFinishLaunching:(UIApplication*)application
{
...
[director setDeviceOrientation:kCCDeviceOrientationPortrait];

Upvotes: 1

Alexander Blunck
Alexander Blunck

Reputation: 1223

I have a better solution that will work 100%:

Replace all the stuff that was in the RootViewController.m / shouldAutorotateToInterfaceOrientation Method with following:

return ( UIInterfaceOrientationIsPortrait( interfaceOrientation ) );

And if I ever want to change the orientation during runtime / switching scene:

[[CCDirector sharedDirector] setDeviceOrientation:CCDeviceOrientationLandscapeLeft];

Note that Auto Rotation is now on longer supported

Upvotes: 6

Anish
Anish

Reputation: 2927

In RootViewController.m

return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) );

change this line to

return ( UIInterfaceOrientationIsPortrait( interfaceOrientation ) );

Upvotes: 0

azamsharp
azamsharp

Reputation: 20094

Inside the RootViewController return false from the method below:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    return false; 

   // other code...

}

Upvotes: 0

Related Questions