Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Igor_F_1
Beginner
522 Views

How to disable screen orientation change in Cocos2D?

Jump to solution

Hello,

   I am playing with iXDK and using integrated Cocos2D engine to create Android, iOS and Win applications/games. I posted a question in title on Cocos forums (http://discuss.cocos2d-x.org/t/how-to-disable-screen-orientation-change/27048) and received a following reply:

To disable orientation changes:

  • on iOS in xCode go to ProjectSettings -> General Tab, here you can find 'Device orientation' settings.
    Or you can directly modify Info.plist:
<key>UISupportedInterfaceOrientations</key>
<array>
	<string>UIInterfaceOrientationPortrait</string>
</array>
  • on android find AndroidManifest.xml and add/edit next properties for main activity (android:screenOrientation & android:configChanges)
<activity
            android:name="org.cocos2dx.cpp.AppActivity"
            android:screenOrientation="portrait"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

 

 

 

 

 How do I implement these changes using Intel XDK and is this correct way to handle this problem?

  I already used Build settings in Project tab, to set orientation on all platforms but this did not have a desired effect. I use Android (no Crosswalk) and iOS build options.

Tags (2)
0 Kudos
1 Solution
Rakshith_K_Intel
Employee
522 Views

setting orientation=portrait in build settings will lock the orientation when you build and install the app, let me know if this is not working, please send me the apk

View solution in original post

6 Replies
Rakshith_K_Intel
Employee
522 Views

Setting orientation=portrait in Intel XDK build settings will do the same changes in info.plist and androidmanifest.xml.

Check your cocos2d game setup:

cc.view.setDesignResolutionSize(width, height, cc.ResolutionPolicy.SHOW_ALL);
cc.view.resizeWithBrowserSize(true);

 

 

Igor_F_1
Beginner
522 Views

I agree there might be a problem in my code but I created Landscape HTML+Cordova game from templates. It works as expected in emulator. Then I went to project options and changed all to portrait (all 4) but application did not change to portrait. I tried changing port./land. options for current project as well, but it did not change anything in emulator.

So port./land. setting works on initial creation of project but not on subsequent changes or is anything needed to apply those changes?

Rakshith_K_Intel
Employee
522 Views

if u notice the portrait and landscape cocos2d templates, it has different width and height values, you have to change that depending on the orientation:

cc.view.setDesignResolutionSize(width, height, cc.ResolutionPolicy.SHOW_ALL);

Igor_F_1
Beginner
522 Views

This did solve the problem of changing resolution but my original question was (as in title) how to disable orientation change when rotating device that causes applications graphics screen to change dimensions. Meaning I would like my game screen to stay exactly the same as before rotation of device. Is this possible and if it is, how is it done?

Rakshith_K_Intel
Employee
523 Views

setting orientation=portrait in build settings will lock the orientation when you build and install the app, let me know if this is not working, please send me the apk

View solution in original post

Igor_F_1
Beginner
522 Views

Tank you for your answers, they helped reveal the problem.

It is true I did not test apk file at all, just emulator and weinre test over wireless. However both emulator and weinre will rotate screen unlike apk application. apk file was installed on to a same device as weinre, no changes were made to source code or settings between tests.

Reply