我正在开发一个 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);它不像我预期的那样工作。如果我快速移动鼠标,光标的位置仍然会移动,然后它会重置到屏幕中间。我也尝试将光标捕获设置为true,但这只会使光标不可见。 Gdx.input.setCursorCatched(true);我希望鼠标光标始终放在屏幕中间,然后根据鼠标移动 3d 移动对象。
1 回答

慕娘9325324
TA贡献1783条经验 获得超4个赞
使用Gdx.input.setCursorCatched(true)但然后在鼠标被抓住时将鼠标十字准线绘制到屏幕中心,并在您松开鼠标时将其移除。
根据您设置游戏的方式,您的十字准线应该是您最后渲染的东西之一:
public void render() {
...
spriteBatch.render(cursor, Gdx.graphics.getWidth()-cursorSize.x)/2,(Gdx.graphics.getHeight()-cursorSize.y)/2);
spriteBatch.end();
}
添加回答
举报
0/150
提交
取消