2017-02-21 43 views
3
table.setPosition(0, 0); 
table.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); 
table.setTouchable(Touchable.enabled); 
table.addListener(new ClickListener(){ 
    @Override 
    public void touchUp (InputEvent event, float x, float y, int pointer, int button) { 
     System.out.println("me working"); 
     nextPhrase(); 
    } 
}); 
stage.addActor(table); 

touchUp方法不觸發。表格包含圖像和標籤並填充屏幕。我需要nextPhrase()方法觸發屏幕時觸發。我該怎麼辦?爲什麼touchUp方法不觸發?

+0

我不知道libgdx,但我讀到那裏(http://stackoverflow.com/questions/35287866/libgdx-how-to-handle-touch-event),你需要一個InputListener而不是ClickListener(它會聽取點擊,我相信) –

回答

3

我不知道你的完整代碼,但我認爲你忘記了更新你的Stage。如果是,請將其放在渲染/更新方法中。這樣做是更新舞臺內的所有Actors

stage.act(); 

此外,不要忘記設置您的輸入處理器來讀取用戶的輸入。

Gdx.input.setInputProcessor(stage); 
+0

謝謝!我有stage.act(),但我忘了設置InputProcessor。 –

+0

我很高興它的工作原理。另外,不要忘記接受答案。 :d – Sparcsky

0

如果touchDown返回true,touchUp將被觸發。否則,不再跟蹤觸摸。

但是,我會推薦實施「點擊」功能,而不是touchUp功能,它可以爲您處理。

相關問題