0
我已经发布了这个question之前,但似乎我无处可去,即使我确实得到了很多人的帮助。所以我做了一个小实验。我创建了一个测试项目来测试LibGdx触摸处理。这touchTester项目以某种方式复制我的问题。附件(附件删除)请找到整个项目源代码(压缩文件)。以下代码中的upCounter应该只返回1,因为它只应该需要运行一次。libgdx演员touchHandling问题
// upCounter is = 0;
this.libgdxImg.addListener(new InputListener() {
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
return true;
}
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
upCounter++;
touchtester.doLog("upCounter = " + upCounter);
}
});
然而,当我运行它,它给了我这样的结果
catland: touchTester: render
catland: touchTester: render
catland: touchTester: upCounter = 1
catland: touchTester: upCounter = 2
...
catland: touchTester: upCounter = 94
catland: touchTester: upCounter = 95
catland: touchTester: render
catland: touchTester: render
请问别人的帮助来试一下吗?我完全不知道问题出在哪里。我使用gdx-setup-ui.jar文件设置我的项目。
Thanks @noone。有道理。但是,如果我将这些代码放在show()方法中,在应用程序会话期间如何禁用/重新启用按钮/ InputListener? – Ziiiii
'this.libgdxImg.cleaerListeners()',或者通过禁用整个阶段'Gdx.input.setInputProcessor(null)' – noone
Thanks @noone,那么重新启用它呢? – Ziiiii