我正在做一个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不可逆。Gdx.input.setCursorCatched(true);
我希望鼠标光标始终放在屏幕的中间,然后根据鼠标的移动来3d移动对象。
发布于 2019-04-16 17:15:39
使用Gdx.input.setCursorCatched(true),然后在鼠标被捕获时将鼠标十字线绘制到屏幕的中心,并在未捕获鼠标时将其移除。
根据你如何设置你的游戏,你的十字准线应该是你渲染的最后的东西之一:
public void render() {
...
spriteBatch.render(cursor, Gdx.graphics.getWidth()-cursorSize.x)/2,(Gdx.graphics.getHeight()-cursorSize.y)/2);
spriteBatch.end();
}https://stackoverflow.com/questions/55696230
复制相似问题