0
\$\begingroup\$

I am trying to build a card based game in which a card is added to player after every round. To win the match player has to remove all cards from his deck. However I have also drawn some additional button for some other purposes. The issue is that when the number of cards got high, they hide behind the buttons like below image.

enter image description here

Is there any way through which i can draw the bitmaps in a fixed area? Something like below image (highlighted rectangle behind the card images).

enter image description here

Following is my code to draw Bitmaps for one player

private void setMainPlayer() {
    //    Log.d(TAG, "Inside Set Main Player Method");
    Card localcard = null;
    Bitmap localimage = null;
    int currentiteration = 0;
    int Card_Gap = Screen_Width / 10;
    int Down_Card_Gap = 0;
    int Down_Card_Gap_positive = 0;
    int Down_Card_Gap_negative = 0;
    playerList.get(0).sortBySuit();

    //  Log.d(TAG,"Main Player Deck size"+MainPlayer.Count());
    while (currentiteration < playerList.get(0).decksize()) {
        localcard = playerList.get(0).getCard(currentiteration);
        localcard.setCurrent_Y(Screen_Height - localcard.getImage(context, Card_Width, Card_Height).getHeight());
        playerList.get(0).setCurrentCard(localcard, currentiteration);
        currentiteration++;
        if (Down_Card_Gap >= 0) {
            Down_Card_Gap_positive = Down_Card_Gap;
            localcard.setCurrent_X(Screen_Center_X + Down_Card_Gap_positive);
            Down_Card_Gap += Card_Gap;
        } else {
            Down_Card_Gap_negative = Down_Card_Gap;
            localcard.setCurrent_X(Screen_Center_X + Down_Card_Gap_negative);
        }
        Down_Card_Gap *= -1;

    }


}

private void DrawMainPlayerDeck(Canvas canvas) {
    // Log.d(TAG, " Inside Draw Main Player Deck");
    Card localcard;
    int currentiteration = 0;
    while (currentiteration < playerList.get(0).decksize()) {
        localcard = playerList.get(0).getCard(currentiteration);
        canvas.drawBitmap(localcard.getImage(context, Card_Width, Card_Height), localcard.getCurrent_X(), localcard.getCurrent_Y(), null);
        currentiteration++;
    }



}

I am drawing bitmaps on surfaceview.

Any suggestion (even if it involves a game engine like libGDX) would be really helpful.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

Most cards are designed in a way that lets you tell what it is by seeing very little of them. Most cards do this by having the symbols in the upper left and lower right corners. Due to this, you can stack them up pretty tightly before it becomes a problem.

There are two approaches you can take:

1.) Have them always stacked up. You can make the distance between the edges really small, this way you can store a bunch of cards in that rectangular area and simply not bother limiting it.

2.) Make the distance dynamic. If we know the cards have to go from x=100 to x=900 on the screen for instance, and we have 20 cards we need to display, then obviously the first one has to go to x=100 ans the last to x=900. The remaining can be placed based on a simple linear interpolation. If \$n\$ is the number of cards on the table, then the position of any card with the index \$i\$ is:

$$100 + i\cdot \frac{900 - 100}{n}$$

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .