4

When trying to put a simple ImageButton on stage, It didn't seem to detect clicks.

ImageButton btnStart = new ImageButton(ButtonArt.UP, ButtonArt.DOWN));

// btnStart.setClickListener(new ClickListener() {
//          @Override
//          public void click(Actor a, float arg1, float arg2) {
//             a.visible = false;
//          }
//       });

stage.addActor(btnStart);

ButtonArt.UP and ButtonArt.DOWN are TextureRegions, of each state. Now when I click on the button, it doesn't change state! I also tried the above ClickListener (for testing), but it seemed that didn't work either.

In my render method I just call stage.act() and stage.render(). I also tried drawing the TextureRegions with SpriteBatch in my render method, and they are in fact different textures.

Am I doing something wrong?

Daahrien
  • 10,190
  • 6
  • 39
  • 71
user717572
  • 3,626
  • 7
  • 35
  • 60

1 Answers1

8

You will need to set the stage as your inputprocessor:

Gdx.input.setInputProcessor(stage);

If you need to have multiple inputprocessors (e.g., you need clicks registered outside your scene), you will need to use an InputMultiplexer, like this:

InputMultiplexer plex = new InputMultiplexer();
plex.addProcessor(myOtherProcessor);
plex.addProcessor(stage);
Gdx.input.setInputProcessor(plex);
Matsemann
  • 21,083
  • 19
  • 56
  • 89