Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Libgdx why is my button not responding on mouseclicks

Why is my TextButton, from libgdx not responding on clicks?

I have a button, this button has a Listener, but it doesn't respond. The button is showing, but it doesn't respond on 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);
}
like image 801
Abdelkarim Abdoe Avatar asked Dec 06 '22 08:12

Abdelkarim Abdoe


1 Answers

Add a ClickListener to your button. It'll 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 stage to be an input processor, otherwise it won't see the events.

Gdx.input.setInputProcessor(stage);
like image 188
Rod Hyde Avatar answered Dec 31 '22 11:12

Rod Hyde