LibGDX输入模块之光标可见性和捕捉

对于像第一人称射击游戏的游戏来说,通常需要捕捉光标,使其停留在屏幕中央,并且仅使用位置三角形来旋转相机。 其他时候,我们可能需要手动放置光标。 这两件事情都可以做到如下:

Gdx.input.setCursorCatched(true);
Gdx.input.setCursorPosition(x, y);

注意,光标捕捉和定位仅在桌面上可用。捕捉光标只能在Lwjgl后端可靠地工作。 Jogl后端可能会有一些意想不到的问题。

类似地,如果浏览器支持“cursor:url()”语法,并且还支持png格式作为游标,则可以在桌面和gwt上更改光标图像。 可以做到如下:

注意:如果您不再需要,您应该销毁光标

Cursor customCursor = Gdx.graphics.newCursor(new Pixmap(Gdx.files.internal("cursor.png")), hotspotX, hotspotY);
Gdx.graphics.setCursor(customCursor);

您也可以将光标更改为系统光标,这仅适用于LWJGL3后端和GWT后端。 可以做到如下:

Gdx.graphics.setSystemCursor(SystemCursor.Crosshair);

支持的系统光标如下:

Arrow


Image of an arrow cursor

Ibeam


Image of an i-beam cursor

Crosshair
Image of a crosshair cursor

Hand


Image of a pointer cursor

HorizontalResize
Image of a horizontal-resize cursor

VerticalResize
Image of a vertical-resize cursor

你可能感兴趣的:(LibGDX输入模块之光标可见性和捕捉)