我正在製作一個LibGdx遊戲。我有一個主菜單和一個按鈕,用於將用戶發送到播放屏幕。在玩遊戲畫面時,遊戲反應與用戶點擊按鈕位於前一屏幕中的位置時的反應。下面是定義按鈕切換屏幕代碼:LibGdx新屏幕反應從舊屏幕觸摸
button = new TextButton("Play", button_text);
button.setWidth(Gdx.graphics.getWidth()/4);
button.setHeight(Gdx.graphics.getHeight()/8);
button.setPosition((Gdx.graphics.getWidth()/2) - (button.getWidth()/2), (Gdx.graphics.getHeight()/2) - (button.getHeight()/2));
stage.addActor(button);
Gdx.input.setInputProcessor(stage);
button.addListener(new InputListener(){
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button){
game.setScreen(new PlayScreen(game));
dispose();
return true;
}
});
下面是該屏幕的Dispose方法:
@Override
public void dispose() {
stage.dispose();
}
那麼,如何從一個屏幕移動到下一個前清除所有輸入?
你可以發佈PlayScreen類及其偵聽器方法嗎?可能是誤解觸摸事件的一個問題。 (爲了快速解決問題,我認爲你有,可以將touchDown方法更改爲touchUp以上?) – 2014-10-10 06:28:22
我找到了解決方案,並將其發佈爲答案 – 2014-10-13 22:55:29