我使用带有舞台的 Actor 作为按钮。我可以检测到何时 touchDown/touchUp 事件在 actor 上发生得很好,但是当用户点击 actor 然后继续将他们的手指从 actor 上拖开时,touchUp 事件永远不会触发。我尝试改用退出事件,但它从未触发。在我的程序中,touchUp/touchDown 事件确定移动以及按钮颜色,这取决于按钮是否被按下。所以我留下了一个永久“按下”的按钮,直到它再次被向下/向上点击。
我正在使用的代码示例:
stage.addListener(new InputListener() {
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
Actor actor = stage.hit(x, y, true);
if (actor != null){
System.out.println("touchDown: " + actor.getName().toString());
}
return true;
}
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
Actor actor = stage.hit(x, y, true);
if (actor != null){
System.out.println("touchUp: " + actor.getName().toString());
}
}
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor){
System.out.println("exit");
}
});
最佳答案
如果你改变
stage.addListener(new InputListener() {});
到
stage.addListener(new ClickListener() {});
它将识别 TouchUp 调用。它仍然能够处理 TouchDown 和 Exit 调用。
关于java - libgdx touchUp 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13202753/