Reputation: 1134
In My Code: I created a Table();
contains a many of buttons and labels inside Stack();
(libGDX's Stack).
table = new Table();
table.setFillParent(true);
Stack[][] stackTable = new Stack[LENGHT_TILE][LENGHT_TILE];
Label[][] lbl = new Label[LENGHT_TILE][LENGHT_TILE];
Button[][] btnSquares = new Button[LENGHT_TILE][LENGHT_TILE];
for (int row = 0; row < btnSquares.length; row++) {
for (int col = 0; col < btnSquares[0].length; col++) {
lbl[row][col] = new Label("" + array[row][col], style);
lbl[row][col].setAlignment(Align.center);
lbl[row][col].setTouchable(Touchable.disabled);
btnSquares[row][col] = new Button(new Image(texture).getDrawable());
stackTable[row][col] = new Stack();
stackTable[row][col].add(btnSquares[row][col]);
stackTable[row][col].add(lbl[row][col]);
table.add(stackTable[row][col]);
}
}
stage.addActor(table);
I CAN'T modify the widths, heights, sizes and scales of these buttons or labels. WHY ??
Upvotes: 0
Views: 37
Reputation: 8584
I do not understand what you are doing here. Why would you need to store all those actors in multidimensional arrays? I advice you to start a bit smaller:
Table table = new Table();
Stack stack = new Stack();
TextButton frontButton = new TextButton("Front", skin);
TextButton backButton = new TextButton("Back", skin);
stack.add(backButton);
stack.add(frontButton);
//Now this should work fine
table.add(stack).height(...).expandX(...).fillX().row();
Are you storing your buttons in these actors for later reference? If you want to make somkind of tile system or raster then Table is perfectly capable of making that without all these multi dimensional arrays. So I'm not sure what you are trying to accomplish here but it looks wrong or overly complicated If a Stack, Label and Button are related I'd make a container class for this.
Class MyContainer()
{
Stack stack;
Label label;
Button button;
//Getters & setters
//...
public MyContainer(Stack stack, Label label, Button button)
{
this.stack = stack;
//...
}
}
Now instead of adding in the multidimensional arrays you can add them into a container and add these in a list. You can add listeners for your actors in this class and all is nice and contained.
Upvotes: 1