Search code examples
javaandroidlibgdxbox2dscene2d

Libgdx | Scene2d | touchDown input processor method not firing when clicking invisible button


I have created a restart button, then added it to a table. When I set the table to invisible, and click where the restart button is located (now invisible) then the touchDown InputProcessor in my player class doesn't even fire. However, when I click elsewhere, it does fire the player touchDown. Somehow this button is interfering even though it is invisible. Some extra info:

-My button is a custom class, I will put code below
-Restart button has a clickListener, however, removing this doesn't fix the problem
-The table is on a separate stage and viewport then the player

CustomButton code (for the restart button) :

class CustomDrawable implements Drawable {

private Sprite sprite;
private Actor actor;

public CustomDrawable(Actor actor, Sprite sprite) {
    this.actor = actor;
    this.sprite = sprite;
}

@Override
public void draw(Batch batch, float x, float y, float width, float height) {
    sprite.setPosition(x, y);
    sprite.setSize(width, height);
    sprite.setColor(actor.getColor());
    sprite.draw(batch);
}
}

Solution

  • Call setTouchable(Touchable.disabled) on the restart button when you make it invisible. (And enable it when making it visible.)