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