Skip to content Skip to sidebar Skip to footer

How To Stop Drawing A Spritebatch Animation In Libgdx?

Hi I have a spritebatch animation in Libgdx. It only plays once and when it is finished I want to stop drawing it so it doesn't appear on the screen. I have a boolean that checks

Solution 1:

The problem I see is that you always declare a new boolean variable "alive" and set the alive to true at the beginning:

booleanalive=true;

and then all your drawing is happening and after all that you set alive to false if your animation is finished:

if(walkAnimation.isAnimationFinished(stateTime))
    alive = false;

==> That is too late, because after this you don't do anything anymore with this local variable.


You could for example check if "alive" should be true or false right at the beginning and set its value accordingly, like for example:

booleanalive=true;
 if(walkAnimation.isAnimationFinished(stateTime)) {
    alive = false;
 }
 //your drawing code below..

alternatively you could make "alive" a field instead of a local variable.

Post a Comment for "How To Stop Drawing A Spritebatch Animation In Libgdx?"