[ad_1]
Warning – this isn’t the most effective method, nevertheless it’s for UI
studying functions.
As I can see you retain your ‘deck’ in a Desk
.
To start with, make a wrapper Desk
which is able to fill the entire display (it will likely be invisible don’t fret):
ultimate Desk fullScreenTable = new Desk();
Set it is dimension to full display w/h and add it to the stage:
stage.add(fullScreenTable);
fullScreenTable.setSize(Gdx.graphics.getWidth, Gdx.graphics.getHeight());
fullScreenTable.backside(); // bear in mind about this, it'll drive including elements to the underside of the desk.
Now for the participant, additionally make a Desk
, like this:
ultimate Desk playersTable = new Desk();
now, add the desk to the display Desk like this:
fullScreenTable.add(playersTable).dimension(Gdx.graphics.getWidth(), 250);
playersTable.debug(); // calling debug will allow debug strains so you will see the place your desk is (trigger it is invisible D:)
Your playersTable
is now on the underside of the display. When you add a component to it, it will likely be positioned on the middle of the desk and the subsequent ingredient might be positioned on the precise of the earlier.
Now, when you’ve your record with the playing cards:
public void rebuildHand(){
playersTable.clear(); // it'll clear the desk from earlier playing cards
for (int i = 0; i < handPlayer1.dimension(); i++) {
Card card = handPlayer1.get(i);
// we should 'pad' the cardboard to the left, trigger in any other case they're going to stick to one another
ultimate float cardPadding = card.getWidth() - 10;
playersTable.add(card).dimension(card.getWidth(), card.getHeight()).padLeft(-cardPadding);
// or if it would not work name .padRight(cardPadding);
}
}
The code above clears the desk (it would not take away your playing cards from the reminiscence, don’t fret). When you ‘draw a card’ or ‘play a card’ you must name the operate above and it’ll rebuild the entire desk, bringing all playing cards collectively (however keep in mind that if you draw a card, you must add it to the handPlayer1
record and in the event you play a card, it’s important to take away it from the record.
This manner, there might be no areas between playing cards in the event you play one and you’ll draw extra playing cards now trigger they’re going to stick to one another with each draw.
If it is nonetheless not enought – you may set a MAX_CARDS_IN_HAND variable or make a brand new row() within the Desk in case your playing cards is simply too massive and place subsequent playing cards beneath them (two rows).
Examine Desk UI right here: https://github.com/libgdx/libgdx/wiki/Desk
[ad_2]