【发布时间】:2012-10-23 13:20:48
【问题描述】:
我正在使用带有舞台作为按钮的演员。我可以检测到 touchDown/touchUp 事件何时在演员身上发生得很好,但是当用户点击演员然后继续将他们的手指从演员身上拖出时,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");
}
});
【问题讨论】:
-
您使用的是什么版本的 libgdx?最新的好像没有
Stage.addListener()。也许这是在比您使用的版本更新的版本中修复的错误。 -
我正在使用 2012 年 10 月 20 日的夜间版本,libgdx.txt 说它是 0.9.3,然后我会尝试 0.9.6。
-
啊。好吧,我不太熟悉流血的边缘。如果我不得不猜测,我会说实现
touchDragged()可能会有所帮助。 -
我也试过了:),但运气不好,它永远不会触发。
标签: java events libgdx actor stage