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 if it is still alive i.e. animating and it is set to false when the animation is finished using isAnimationFinished however it stays on the screen and I am not sure why even though a log print shows it changing to false on finish. Does anyone have any idea why this is? Thanks for your help. The following code is from my render method.
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); // This cryptic line clears the screen.
boolean alive = true;
stateTime += Gdx.graphics.getDeltaTime(); // #15
currentFrame = walkAnimation.getKeyFrame(stateTime, false); // #16
spriteBatch.begin();
spriteBatch.draw(menu, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
if (alive)
spriteBatch.draw(currentFrame,50,50);
if(walkAnimation.isAnimationFinished(stateTime))
alive = false;
System.out.println(alive);
spriteBatch.end();
stage.draw();