libGDX 在进入全屏后停止捕捉光标

libGDX's stops being able to catch cursor after entering fullscreen

我正在写一个 libGDX 小游戏。使用 setCursorCatched(boolean) 捕获光标一开始效果很好(隐藏光标符号,不会让我转义 window),但随后中断:

完整的最小可重现示例(另请参阅 ):

package xjcl.extracredits2020

import com.badlogic.gdx.*

class RangeAnxietyGame : ApplicationAdapter() {
    override fun create() {
        Gdx.input.apply { isCursorCatched = true }
    }

    override fun render() {
        if (Gdx.input.isKeyPressed(Input.Keys.F))
            Gdx.graphics.setFullscreenMode(Gdx.graphics.displayMode)
        if (Gdx.input.isKeyPressed(Input.Keys.G))
            Gdx.graphics.setWindowedMode(1280, 720)
        if (Gdx.input.isKeyPressed(Input.Keys.ESCAPE))
            Gdx.app.exit()

        Gdx.input.setCursorPosition(Gdx.graphics.width/2, Gdx.graphics.height/2)
    }
}

有什么方法可以强制光标保持被 libGDX window 捕获?

根据 @Tenfour04 的建议,从 lwjgl 切换到 lwjgl3 可以解决问题![​​=28=]

build.gradle中将第一块改成第二块:

api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
api "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"

同时调整您的导入(例如在 DesktopLauncher class):

import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;

在我的例子中,我还需要更新 DesktopLauncher:

的配置
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.samples = 8;
config.height = 720;
config.width = 1280;
config.vSyncEnabled = true;
new LwjglApplication(new RangeAnxietyGame(), config);
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
config.setBackBufferConfig(8, 8, 8, 8, 16, 0, 8);
config.setWindowedMode(1280, 720);
config.useVsync(true);
new Lwjgl3Application(new RangeAnxietyGame(), config);