Search code examples
javaandroidlibgdxlandscape-portrait

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?


Solution

  • 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