Libgdx 更改 window 大小而不禁用在桌面上调整大小
Libgdx changing window size without disabling resize on desktop
我一直在尝试通过阅读他们喜欢的 window 大小来调整游戏中 window 的大小。现在,设置完成后,用户将无法再调整游戏大小。我使用此代码调整 window:
的大小
//userWidth and userHeight are both intergers already initialized.
DisplayMode desktopDisplayMode = Gdx.graphics
.getDesktopDisplayMode();
Gdx.graphics.setDisplayMode(userWidth,
userHeight, true);
我尝试将 window 调整大小的代码放入 DesktopLauncher.java 文件,但我无法使用 Gdx.app.getPreferences()
,因为它会引发错误。
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.height = userHeight;
config.width = userWidth;
有没有其他方法可以调整 window 的大小,或者有没有办法让 window 再次调整大小?
这是 LibGDX 中的错误:
https://github.com/libgdx/libgdx/issues/2635
如您所见,它已在 v.1.5.1 中修复,因此只需在您的项目中更新 libGDX。
如果您使用的是 Gradle,这很简单,只需更新 build.gradle 文件中的 gdxVersion:
allprojects {
...
ext {
...
gdxVersion = '1.5.1'
}
}
我一直在尝试通过阅读他们喜欢的 window 大小来调整游戏中 window 的大小。现在,设置完成后,用户将无法再调整游戏大小。我使用此代码调整 window:
的大小//userWidth and userHeight are both intergers already initialized.
DisplayMode desktopDisplayMode = Gdx.graphics
.getDesktopDisplayMode();
Gdx.graphics.setDisplayMode(userWidth,
userHeight, true);
我尝试将 window 调整大小的代码放入 DesktopLauncher.java 文件,但我无法使用 Gdx.app.getPreferences()
,因为它会引发错误。
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.height = userHeight;
config.width = userWidth;
有没有其他方法可以调整 window 的大小,或者有没有办法让 window 再次调整大小?
这是 LibGDX 中的错误: https://github.com/libgdx/libgdx/issues/2635
如您所见,它已在 v.1.5.1 中修复,因此只需在您的项目中更新 libGDX。 如果您使用的是 Gradle,这很简单,只需更新 build.gradle 文件中的 gdxVersion:
allprojects {
...
ext {
...
gdxVersion = '1.5.1'
}
}