Search code examples
libgdx

LibGDX - Actors on top of each other, avoid two draw calls


I am writing a card game with multiple cards that will stack up on the unplayed deck, and also on 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 off each player's hand.

I'm hoping someone can tell me off 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?


Solution

  • To save a lot of computation you could just render the image of the cards 6 times. If a card is being dealt just render a 7th being moved across the screen. This avoids calling the draw method of a large number of objects.