如何使用 libGDX 在纵向和横向模式之间切换?

How to switch between portrait and landscape mode with libGDX?

我创建了一款在桌面模式下运行良好的游戏。但是当我 运行 它在移动设备上时,它 运行 仅处于横向模式。如何让游戏在竖屏和横屏模式下都能正常运行?

打开位于 Android 项目中的 AndroidManifest.xml 并找到内容为:

的条目
android:screenOrientation="landscape"

将 "landscape" 更改为 "portrait" 使其看起来像这样:

android:screenOrientation="portrait"

在 AndroidManifest.xml 文件中将 screenOrientation 设置为 fullSensor:

android:screenOrientation="fullSensor"

这将检测设备的方向并自动旋转屏幕。 LibGDX 中的 ViewPorts 还用于确定您的程序在屏幕旋转时如何处理宽度和高度的变化。 https://github.com/libgdx/libgdx/wiki/Viewports