然后不使用输入多路复用器,而是使用以下代码:
public class MyGestureDetector extends GestureDetector {
public MyGestureDetector(GestureListener listener) {
super(listener);
}
@Override
public boolean touchUp(float x, float y, int pointer, int button) {
super.touchUp(x, y, pointer, button);
// Your Code Here
return true;
}
}
类似地,可以在此处添加其他功能,例如 touchdown 等,不要忘记从功能中调用 super,因为这将使各种功能(例如 fling 和 tap)工作
编辑:
将实现更改为
public class MyGestureDetector extends GestureDetector {
private Stage stage;
public MyGestureDetector(GestureListener listener,Stage stage) {
super(listener);
this.stage = stage;
}
@Override
public boolean keyDown(int keycode) {
stage.keyDown(keycode);
super.keyDown(keycode);
return false;
}
@Override
public boolean keyUp(int keycode) {
stage.keyUp(keycode);
super.keyUp(keycode);
// TODO Auto-generated method stub
return false;
}
@Override
public boolean keyTyped(char character) {
// TODO Auto-generated method stub
stage.keyTyped(character);
super.keyTyped(character);
return false;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
stage.touchDown(screenX, screenY, pointer, button);
super.touchDown(screenX, screenY, pointer, button);
return false;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
stage.touchUp(screenX, screenY, pointer, button);
super.touchUp(screenX, screenY, pointer, button);
return false;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
// TODO Auto-generated method stub
stage.touchDragged(screenX, screenY, pointer);
super.touchDragged(screenX, screenY, pointer);
return false;
}
@Override
public boolean mouseMoved(int screenX, int screenY) {
stage.mouseMoved(screenX, screenY);
super.mouseMoved(screenX, screenY);
return false;
}
@Override
public boolean scrolled(int amount) {
stage.scrolled(amount);
super.scrolled(amount);
// TODO Auto-generated method stub
return false;
}
}
这里的 stage 是 scene2d Stage,根据您使用的 libgdx 版本,参数中可能存在一些 float 或 int 错误,这是用 0.9.9 nightlies 编写的
PS-此实现是根据您的问题定制的,但应该尝试通过返回 true 或 false 来处理每个案例,如前所述