Libgdx why my button does not respond to mouseclicks

Why is my TextButton from libgdx not responding to clicks?

I have a button, this button has a Listener, but it does not respond. The button is displayed, but it does not respond to mouse clicks.

 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); } 
+4
source share
1 answer

Add a ClickListener button to your button. It will look something like this.

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

Also, make sure that you set the scene as the input processor, otherwise it will not see the event.

 Gdx.input.setInputProcessor(stage); 
+15
source

All Articles