[英]Getting input from the onscreen Keyboard using libgdx
我正在尝试编写游戏,如果他们做某事,它将启动屏幕键盘。 然后,如果他们触摸了几个键,游戏将把场景切换到奖励级别。 我目前正在使用libgdx,它在带有真实键盘的桌面版本上效果很好。 我无法在Android版本上使用它。
在render方法中:
if (Gdx.input.isTouched()) {
Vector3 touchPos = new Vector3();
touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
camera.unproject(touchPos);
...
} else if (touchPos.x > 0 && touchPos.x < 200
&& touchPos.y > 0 && touchPos.y < 50) {
Gdx.input.setOnscreenKeyboardVisible(true);
}
这很好。 这样做的全部目的是使键盘显示出来。 它确实做到了。 但是,当我尝试使用以下命令检测按键时:
if (Gdx.input.isKeyPressed(Keys.A)) {
// Do What I need it to do.
}
我从来没有真正的价值。 无论什么键或值。 如何从libGDX中的屏幕Android键盘检测按键?
Gdx.input.isKeyPressed
正在轮询键盘的状态,因此只有在实际按下该键时它才为true。 屏幕键盘甚至无法报告该状态。
切换到InputProcessor
可以使每个键盘事件作为一个InputProcessor
事件传递。
有关更多详细信息,请参见http://code.google.com/p/libgdx/wiki/InputEvent 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.