Spylot Spylot - 4 months ago 16
Java Question

Updating a table's cell with an ImageButton in LibGDX?

I have a class that initiates a table with 3 cells filled like so:

[leftButton] [ImageButton] [rightButton]

ImageButton is created & added to characterSelection array:

Texture characters2 = TrafficGame.res.getTexture("chevy");
characterImageStyle = new ImageButton.ImageButtonStyle();
car = new TextureRegion(characters2, 32, 32);
characterImageStyle.imageUp = new TextureRegionDrawable(new TextureRegion(car));
characterImageChevy = new ImageButton(characterImageStyle);

Adding to table when player selection is initiated:


Now when the user clicks the left/right button, moveLeft/Right() gets called:

public void moveLeft(){

This where I'm stuck. It obviously clears the cell but I have no idea how to add an ImageButton back to it from the array.


Table doesn't support swapping actors into the same cell. Instead of clearing the image button, you should hide it. When you're ready for it to show another image, change its image and show it.