Search code examples
javaandroidlibgdx

Android Studio Libgdx Game Landscape to portrait


I programmed an android game, with Libgdx, and now I am the end. I realized I have to switch to portrait mode. I tried to do it through AndroidManifest.xml, with "android:screenOrientation", but my app crashes. I used the width and height of the screen in many situations, as well as the assets width and height, so my question is, how does "android:screenOrientation" actually work? It switches the height of everything with the width? I am a bit confused about this and I don't know how to switch to portrait mode with a code so big.


Solution

  • Dan, android:screenOrientation (for libgdx) forces the application to set its width and height (Gdx.graphics.getWidth() / getHeight()) based on the device aspect ratio. Portrait mode sets the smaller side as the width and larger side as height (for example 9:16), landscape the sets the larger side as the width and smaller side as height (16:9).