Jovan
Jovan

Reputation: 4794

libgdx tablelayout add image in new row

I'm using libgdx and table layout in my screens.

When I add images in Table on initialize everything is fine, but when I add image to table on some event (on collision) images are placed in one column not every image in new row.

Table tableCenterLeft;
Image image1, image2;


    private void init() {

       tableCenterLeft = new Table();
       image1 = new Image(Assets.instance.image.image1);
       image1 = new Image(Assets.instance.image.image1);

       createUI();

    }

    private void createUI() {

    //if I add image here in init() image1 and image2 are added one below the other (fine)
       tableCenterLeft.add(image1);
       tableCenterLeft.add(image2);
    }

    private void onCollisionWithRock() {
    // if I add in some event later in game , image1 and image2 are in same column (bad)
       tableCenterLeft.add(image1);
    }

Any idea ? Thanks

Upvotes: 0

Views: 908

Answers (1)

Lucien Clement
Lucien Clement

Reputation: 116

You have to call tableCenterLeft.row() before tableCenterLeft.add(image1) if you want your table to have a new line as described in the documentation.

With your method createUI, the two images should be on the same row.

Upvotes: 2

Related Questions