Warning – this isn’t the perfect strategy, nevertheless it’s for UI
studying functions.
As I can see you retain your ‘deck’ in a Desk
.
Initially, make a wrapper Desk
which is able to fill the entire display (it will likely be invisible don’t fret):
last Desk fullScreenTable = new Desk();
Set it is measurement 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's going to power including parts to the underside of the desk.
Now for the participant, additionally make a Desk
like this:
last Desk playersTable = new Desk();
now, add the desk to the display Desk like this:
fullScreenTable.add(playersTable).measurement(Gdx.graphics.getWidth(), 250);
playersTable.debug(); // calling debug will allow debug strains so you may see the place your desk is (trigger it is invisible D:)
Your playersTable
is now on the underside of the display. For those who add a component to it, it will likely be positioned on the middle of the desk and the following ingredient will probably be positioned on the appropriate of the earlier.
Now, when you’ve gotten your checklist with the playing cards:
public void rebuildHand(){
playersTable.clear(); // it's going to clear the desk from earlier playing cards
for (int i = 0; i < handPlayer1.measurement(); 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
last float cardPadding = card.getWidth() - 10;
playersTable.add(card).measurement(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). For those who ‘draw a card’ or ‘play a card’ you should 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 should add it to the handPlayer1
checklist and should you play a card, you need to take away it from the checklist.
This fashion, there will probably be no areas between playing cards should 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 can 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