This should be seemingly obvious and simple, but it isn’t for me and seems to be more confusing than you’d think at first.
The Cocos2d template’s GameConfig.h I have set the following:
#if defined(__ARM_NEON__) || TARGET_IPHONE_SIMULATOR
#define GAME_AUTOROTATION kGameAutorotationNone
// ARMv6 (1st and 2nd generation devices): Don't rotate. It is very expensive
#elif __arm__
#define GAME_AUTOROTATION kGameAutorotationNone
// Ignore this value on Mac
#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED)
#else
#error(unknown architecture)
#endif
In the App Delegate applicationDidFinishLaunching I have this:
#if GAME_AUTOROTATION == kGameAutorotationUIViewController
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
#else
[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
#endif
In the RootViewController shouldAutorotateToInterfaceOrientation:
#if GAME_AUTOROTATION==kGameAutorotationNone
//
// EAGLView won't be autorotated.
// Since this method should return YES in at least 1 orientation,
// we return YES only in the Portrait orientation
//
return ( interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
So despite that all conditions for kGameAutorotationNone are set to UIInterfaceOrientationLandscapeLeft, what do I see? Portrait.
What’s is strange is that I can see Landscape Left if I instead shouldAutorotateToInterfaceOrientation to:
#if GAME_AUTOROTATION==kGameAutorotationNone
//
// EAGLView won't be autorotated.
// Since this method should return YES in at least 1 orientation,
// we return YES only in the Portrait orientation
//
return ( interfaceOrientation == UIInterfaceOrientationPortrait);
Can anyone help me understand what is going on here?
The effect you’re seeing comes from the fact that device and interface orientations are switched for the landscape orientations:
That means your device orientation is LandscapeLeft but you don’t allow the RootViewController to rotate to interface orientation LandscapeRight. Therefore it will default to Portrait mode. I suppose if you rotated your device 180° it would suddenly rotate to the device orientation LandscapeRight.
Btw, when you change the autorotation settings in GameConfig.h you don’t need to make any changes to the RootViewController class.