0
嗨我有一個在Libgdx spritebatch動畫。它只播放一次,當它完成後,我想停止繪製它,所以它不會出現在屏幕上。我有一個布爾值,檢查它是否仍然存在,即動畫,當動畫使用isAnimationFinished結束時它被設置爲false,但它仍然保留在屏幕上,我不知道爲什麼即使日誌打印顯示它在完成時更改爲false 。有沒有人有任何想法,爲什麼這是?謝謝你的幫助。以下代碼來自我的渲染方法。如何停止在libgdx中繪製SpriteBatch動畫?
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();
非常感謝您指出。這是我犯的一個愚蠢的錯誤。我做了我的布爾變量全局,而現在它工作正常。 – user2002077