我是libgdx的新手,我在这里想要实现的是我希望我的GestureDetector与InputListener同时工作.我左边有两个按钮,即使我同时开始滑动(多点触控),我也需要它们才能保持反应.我使用InputMultiplexer,但它不能以我需要的方式工作.我检查了InputListener和GestureDetector的所有返回值,我需要的所有东西都返回true,GestureInputListener也是一个实现GestureDetector.GestureListener的类.我只用过它. GestureInputListener和InputListener都可以工作但不能同时工作.你能帮帮我吗?链接,想法.谢谢.代码如下:
inputMultiplexer.addProcessor(stage);
inputMultiplexer.addProcessor(new GestureDetector(gestureInputListener));
Gdx.input.setInputProcessor(inputMultiplexer);
最佳答案 然后代替使用输入多路复用器使用代码:
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;
}
}
类似其他功能,如触地等可以添加在这里不要忘记从功能调用超级,因为这将使各种功能像投掷和点击工作
编辑:
将实现更改为
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,并且在参数中可能会有一些float或int的错误,具体取决于您使用的libgdx版本,这是在0.9.9 nightlies中写的
P.S.-这个实现是根据你的问题定制的,但应该尝试通过返回true或false来处理每个案例,如前所述