我正在使用"Gdx.input.isTouched()"在我的Screen方法的render方法中,以了解触摸的位置,但当触摸在屏幕上拖动时,它也会激活我只想要当一个actor被触摸时才激活的事件。
是否有任何监听器可以知道何时触摸到Actor,但事件不是拖动的事件,我正在使用sprites来实现它。
请参阅此LibGDX中scene2d的维基页面,特别是有关输入处理部分。
基本上,您需要在Actor中覆盖一个或多个以下方法:
public boolean touchDown (float x, float y, int pointer) {
return false;
}
public void touchUp (float x, float y, int pointer) {
}
public void touchDragged (float x, float y, int pointer) {
}
public boolean touchMoved (float x, float y) {
return false;
}
public boolean scrolled (int amount) {
return false;
}
public boolean keyDown (int keycode) {
return false;
}
public boolean keyUp (int keycode) {
return false;
}
public boolean keyTyped (char character) {
return false;
}
Actor
内部有一个监听器。
例如,如果您想要检查按钮何时被按下或选中,您可以调用:button.isPressed()
,button.isCheck()
,它会返回布尔值。我认为当你有多个角色时,你需要在舞台上进行控制。
我认为您需要实现以下方法之一,以仅检测用户执行的单次触摸,而不是移动事件。
Gdx.input.justTouched();