So I am attempting to make a an image of a closed door for a ship. On clicking this door, it would then change to an open door. However, I am struggling to get the click listener to work for the Image. Weirdly, if i use a textbutton instead it works, with pretty much the same code. Below is the class in which a stage is created and the Image actor added to it.

    public class battleScreenActorOverlay implements Disposable {

public battleScreenActorOverlay(World world, SpriteBatch sb, battleShipScreen syst, float bottomButsH, float viewportWidth, float viewportHeight, List<Float> testDoor) {

    viewport = new ExtendViewport(viewportWidth,viewportHeight, new OrthographicCamera());
    stage = new Stage(viewport, sb);
    shipObjsAt = new TextureAtlas("batScreen/objects/shipObjects.atlas");
    Skin skin2 = new Skin(shipObjsAt);

    Image img = new Image(skin2.getDrawable("doorV"));
    img.addListener(new ClickListener() {
        public void clicked(InputEvent event, float x, float y) {
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("touch down");
            return true;
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("touch up");

    // set Image position and dimensions, then boundaries
    img.setSize(testDoor.get(1)*6, testDoor.get(0)*6);
    System.out.println("gabriel "+img.getX()+" "+img.getY()+" "+img.getWidth()+" "+img.getHeight());

    // add to stage which is then rendered in main class

Then the main class basically does some stuff like this:

public class battleShipScreen implements Screen {

// a load of variable declarations here

public battleShipScreen(MyGdxGame game){

    // create viewport etc



public void genShip(){
    // basically method for setting door positions
    batScreenActs = new battleScreenActorOverlay(world,game.batch,this,margin,gameport.getWorldWidth(),gameport.getWorldHeight(),testDoor); // calls class which creates stage and adds door


public void show() {


public void update(float dt){


public void handleInput(float dt) {
 // classic handle input

public void render(float delta) {

    Gdx.gl.glClearColor((float) 60/255, (float) 181/255, (float) 0/255, (float) 0);    // clears screen
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);                       // clears screen
    // render game map



public void resize(int width, int height) {
    System.out.println("resizing "+height+" by "+width);

public void pause() {


public void resume() {


public void hide() {


public void dispose() {


Sorry for the long post, but I have been trying to sort this out for a few days now and have literally no idea what i am doing wrong. Any help working out how to make an Image actor click listener work would be much appreciated!

  • \$\begingroup\$ Did you check the bounds of your image as opposed to a button? Did you compare printing the bounds of the image and the ones of the button? Also, please have a look at some Java naming conventions (e.g. classes should start uppercase, while methods start lowercase). \$\endgroup\$
    – Ignatiamus
    Feb 8, 2019 at 10:07
  • \$\begingroup\$ So I have printed out the bounds that i am setting before and believe them to be correct. When i change the bounds, the size of the Image also changes so it seems the bounds are set to the same size as the graphical representation of the image. Is the setting of bounds correct? \$\endgroup\$
    – Cameron
    Feb 8, 2019 at 11:19

1 Answer 1


In libgdx each actor should belongs to a parent (for example a stage). in each frame (render method) you should call stage.act() for running touch and stuff for each actor in stage. and for drawing you can call stage.draw(). you call stage.act() one time when you are on init stage. just add stage.act() on render method and it should fix your problem.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .