Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to switch between portrait and landscape mode with libGDX?

I've created a game that is working well in desktop mode. But when I run it in mobile, it runs in landscape mode only. How can I make the game work successfully in both portrait and landscape mode?

like image 973
Sanjay Kumar Avatar asked Mar 13 '15 05:03

Sanjay Kumar


2 Answers

Set the screenOrientation to fullSensor in the AndroidManifest.xml file:

android:screenOrientation="fullSensor"

This will detect the orientation of the device and rotate the screen automatically. Also ViewPorts in LibGDX are used to determine how your program will handle the width and height changes when the screen rotates. https://github.com/libgdx/libgdx/wiki/Viewports

like image 125
Tekkerue Avatar answered Nov 03 '22 14:11

Tekkerue


Open AndroidManifest.xml located in Android project and find the entry that says:

android:screenOrientation="landscape"

Change "landscape" to "portrait" to make it look like this:

android:screenOrientation="portrait"
like image 28
Zohaib Amir Avatar answered Nov 03 '22 12:11

Zohaib Amir