2013-03-31 3 views
4

TextButton, 클릭시 libgdx에서 응답하지 않는 이유는 무엇입니까?Libgdx 왜 내 단추가 마우스 클릭에 응답하지 않습니다

단추가 있지만이 단추에는 수신기가 있지만 응답하지 않습니다. 버튼이 표시되지만 마우스 클릭으로 응답하지 않습니다.

public MyStage extends Stage { 
    ... 
    next.addListener(new InputListener() { 
     @Override 
     public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) 
     { 
      Gdx.app.log(ApothecaryGame.LOG, "Pressed: Next button."); 
      return true; 
     } 
     @Override 
     public void touchUp(InputEvent event, float x, float y, int pointer, int button) { 
      Gdx.app.log(ApothecaryGame.LOG, "Released: Next button."); 
      super.touchUp(event, x, y, pointer, button); 
      nextPage(); 
     } 
    }); 
    this.addActor(next); 
} 
+0

이유를 아는 사람이 있습니까? –

답변

15

버튼에 ClickListener를 추가하십시오. 이런 식으로 보일거야.

button.addListener(new ClickListener() { 
    public void clicked(InputEvent event, float x, float y) { 
     // Do something interesting here... 
    } 
}); 

스테이지를 입력 프로세서로 설정했는지 확인하십시오. 그렇지 않으면 이벤트가 표시되지 않습니다.

Gdx.input.setInputProcessor(stage); 
+1

'public void show() {}'메소드에'Gdx.input.setInputProcessor (stage);'를 추가했는지 확인하십시오 – Till