I am writing a card game with multiple cards that will stack up on the unplayed deck, and also in player hands.

Currently I add all 100 card actors to the screen at the start to make it easier so I don't have to manage adding them when they are needed. They all start on top of each other and some get dealt out to players' hands, which are also just piles of cards. So in theory with a 5 player game there are only 6 cards visible, the deck and the top of each player's hand.

I'm hoping someone can tell me of a clever method to mean that only 6 draw methods get run on the actors that are visible, or do I have to manage all this myself?

If I do, would you suggest adding the actors only when I need them, or adding them invisible and then setting them visible when I need to?

Or another method?


1 Answer 1


Best option is of course having one actor if one is visible on the screen, but the solution below could help you in the future. You can create your own class with a name Card or smth which will extend the Actor class.

After that you can create a variable in that class, for example:

private boolean isOnTop; // set it to false in constructor and create getters and setters

Now you can override the draw() method like this:

public void draw(Batch batch, float parentAlpha){
        super.draw(batch, parentAlpha);

Now, when you create your 100 Card objects, you can set one of your cards to isOnTop and it will be drawn. I hope you get the idea!


You must log in to answer this question.

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