2013-07-23 45 views
1

輸入我把下面的表格按鈕在我MenuScreen.java文件做一個「開始遊戲」按鈕:Inputlistener不處理對演員

// register the button "start game" 
     TextButton startGameButton = new TextButton("Start game", getSkin()); 
     startGameButton.setTouchable(Touchable.enabled); 
     startGameButton.addListener(new InputListener() { 

      public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { 
       System.out.println("down"); 
       Gdx.app.log(HowDrunkAreYou.LOG, "touch d"); 
       return true; 
     } 

      public void touchUp(
       InputEvent event, 
       float x, 
       float y, 
       int pointer, 
       int button) 
      { 
       Gdx.app.log(HowDrunkAreYou.LOG, "touch d"); 
       super.touchUp(event, x, y, pointer, button); 
       game.getSoundManager().play(HowDrunkAreYouSound.CLICK); 
       //game.setScreen(new StartGameScreen(game)); 
      } 
     }); 
     table.add(startGameButton).size(300, 60).uniform().spaceBottom(10); 

出於某種原因,輸入處理程序永遠不會觸發,Java調試程序從不輸入方法。我錯過了什麼?我已經在桌面和Android上測試過它,結果相同。

logcat或控制檯都沒有提供任何有關錯誤的信息。

謝謝!

+2

r使用舞臺?是的,那麼你把Gdx.input.setInputProcessor(stage)放在你的代碼中? – Pranav008

+0

我不這麼認爲。我其實很新。什麼是完全階段,它應該在哪裏?我沒有使用gdx.input.setinputprocessor。 – PeterInvincible

+0

這個鏈接將幫助你。 http://steigert.blogspot.in/2012/03/4-libgdx-tutorial-tablelayout.html現在我可以告訴你的是,你需要做一個階段,添加表格,並通過階段setinputprocessor( )。有關更多詳細信息,請參閱此鏈接,您將瞭解有關舞臺和使用表格的更多信息。 – Pranav008

回答

2

您需要在代碼中使用Gdx.input.setInputProcessor(stage)。這個鏈接將幫助你。 steigert blogspot

現在我可以告訴你的是,你需要製作一個舞臺,添加表格並將舞臺傳遞給setinputprocessor()。有關更多詳細信息,請參閱此鏈接,您將瞭解有關舞臺和使用表格的更多信息。