How to change the orientation to Portrait?

How to change the orientation to Portrait?
0.0 0



How to change the orientation to Portrait?




Which platform are you targeting?


iOS and Android

Isn´t there a ‘setDeviceOrientation’ method anymore?

That´s my code:

pEGLView->setFrameSize(320, 480);

But there is a large black strip at the top!


AFAIK the default orientation is Portrait only. Isn’t it.

Anyways, to change the orientation use the following the steps:-


Open file “

Search for method: shouldAutorotateToInterfaceOrientation:interfaceOrientation

Here you can return value as

UIInterfaceOrientationIsPortrait ( interfaceOrientation ) - For Portrait Mode


UIInterfaceOrientationIsLandscape( interfaceOrientation ) - For Landscape Mode

However this will not work for IOS 6 platform. So for IOS 6, you need to make change the following in the method (supportedInterfaceOrientations)

- (NSUInteger) supportedInterfaceOrientations{ #ifdef __IPHONE_6_0 return UIInterfaceOrientationMaskPortrait; #endif }

Detailed Example

// Override to allow orientations other than the default portrait orientation.
// This method is deprecated on ios6

  • (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    //return UIInterfaceOrientationIsLandscape( interfaceOrientation );
    return UIInterfaceOrientationIsPortrait ( interfaceOrientation );
    // For ios6, use supportedInterfaceOrientations & shouldAutorotate instead
    - (NSUInteger) supportedInterfaceOrientations{ #ifdef __IPHONE_6_0 return UIInterfaceOrientationMaskPortrait; #endif }
    For Android

Open AndroidManifest.xml file

Under Activity add line android:screenOrientation=“portrait” for Portrait mode or android:screenOrientation=“landscape” for landscape mode.

Detailed Example
<activity android:name=".GameName" android:label="string/app_name"
android:theme="android:style/Theme.NoTitleBar.Fullscreen" android:configChanges="orientation"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>

Let me know if anything is still confusion or not working for you.

Best Regards,
Paras Mendiratta


Thanks for the code, Paras, but I thought that cocos2dx had a high level way to define the orientation (something like CCDirector::setDeviceOrientation).

The problem is that I´m developing two games, one landscape and the other portrait.


Then do what Paras said in both games.