如何将鼠标光标定位在屏幕中间并根据鼠标移动移动对象?

How can I position mouse cursor in the middle of the screen and move the object according to mouse movement?

我正在开发一个 3d 游戏,其中光标(十字准线)位于屏幕中央,当您移动鼠标时,对象将根据鼠标旋转(就像在 fps 游戏中一样)。

我已经用自己的十字准线替换了默认十字准线,但我无法将其置于屏幕中心。我已经使用以下方法确定了光标放置的中间位置:

cursorPosition=new Vector2((Gdx.graphics.getWidth()-cursorSize.x)/2,(Gdx.graphics.getHeight()-cursorSize.y)/2);

然后每次调用 render() 方法时我都会应用该位置:
Gdx.input.setCursorPosition((int)cursorPosition.x,(int)cursorPosition.y);
它不像我预期的那样工作。如果我快速移动鼠标,光标的位置仍然会移动,然后它会重置到屏幕中间。
我也试过将 cursor catched 设置为 true,但这只会使 cursor invissble。 Gdx.input.setCursorCatched(true);

我希望鼠标光标始终位于屏幕中间,然后根据鼠标移动来 3d 移动对象。

使用Gdx.input.setCursorCatched(true),然后在鼠标被抓住时将鼠标十字线拉到屏幕中央,并在松开时将其移开。

根据您设置游戏的方式,您的准星应该是您最后渲染的内容之一:

public void render() {
    ...
    spriteBatch.render(cursor, Gdx.graphics.getWidth()-cursorSize.x)/2,(Gdx.graphics.getHeight()-cursorSize.y)/2);
    spriteBatch.end();
}