Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I'm trying to test an ImageButton on an Android device. I can get the button to appear on the screen, but when I press it nothing happens or appears on the log. Here is what I have in the Show() method of a class that implements the Screen class.

public void show() {
    uistage = new Stage();
    Texture tankSprite = new Texture(Gdx.files.internal("TankSpriteBase.png"));     
    tank = new Tank(0, true, tankSprite);
    tank.rect.x = 100;
    tank.rect.y = 100;
    tank.rect.width = 44;
    tank.rect.height = 45;

    dropSound ="drop.wav"));
    rainMusic ="rain.mp3"));


    float w = 800;
    float h = 400;

    camera = new OrthographicCamera();
    camera.setToOrtho(false, w, h);
    batch = new SpriteBatch();
ImageButton.ImageButtonStyle ibs = new ImageButton.ImageButtonStyle();
    ibs.up = new TextureRegionDrawable(
                new TextureRegion(
                        new Texture(Gdx.files.internal("direction_left.png"))));
    ibs.down = new TextureRegionDrawable(
                new TextureRegion(
                        new Texture(Gdx.files.internal("direction_left_pressed.png"))));

    leftButton = new ImageButton(ibs);
    leftButton.addListener(new InputListener() {
        public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
      , "down");
                return true;

        public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
      , "up");
    leftButton.setBounds(0, 0, ibs.up.getMinWidth(), ibs.up.getMinHeight());

  , "Width is "" and height is ";

    background = new Texture(Gdx.files.internal("background.png"));
    background.setFilter(TextureFilter.Linear, TextureFilter.Linear);

    TextureRegion region = new TextureRegion(background, 0, 0, 512, 301);

    sprite = new Sprite(region);
    sprite.setSize(0.9f, 0.9f * sprite.getHeight() / sprite.getWidth());
    sprite.setOrigin(sprite.getWidth()/2, sprite.getHeight()/2);
    sprite.setPosition(-sprite.getWidth()/2, -sprite.getHeight()/2);

Might anyone know why this doesn't appear to be working?

share|improve this question

Oh wow, completely bungled this. I forgot to add:


Why this is important is detailed here. Remember to check your code and read your docs, kids! (Eat your veggies too)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.