Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 951
Nick Avatar asked May 13 '11 03:05

Nick


2 Answers

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

like image 72
Alexander Blunck Avatar answered Oct 14 '22 09:10

Alexander Blunck


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];
like image 32
Aurelien Cobb Avatar answered Oct 14 '22 10:10

Aurelien Cobb