0
我正在關注一本libgdx書。其中,作者使用Animation類來播放動畫。這是相關的代碼:getKeyFrame方法接受一個不斷遞增的浮點數。爲什麼?
public class Flappee{
private float animationTimer = 0;
private static final float FRAME_DURATION=0.25f;
public Flappee(Texture texture){
TextureRegion[][] flappeeTextures = new TextureRegion(texture).split(118,118);
collisionCircle = new Circle(x,y,COLLISION_RADIUS);
this.animation = new Animation(FRAME_DURATION,flappeeTextures[0][0],flappeeTextures[0][1]);
animation.setPlayMode(Animation.PlayMode.LOOP);
}
public void update(float delta){
animationTimer+=delta; //called in render method of ScreenAdapter class
}
public void draw(SpriteBatch batch){
TextureRegion texture = animation.getKeyFrame(animationTimer);
batch.draw(//drawing commands);
}
}
我不明白爲什麼animationTimer需要增加每個渲染循環。正如你所看到的,getKeyFrame
返回正確的textureRegion是至關重要的。我想這與循環同一動畫一直有關。我可以要求關於這個話題的更多解釋嗎?
是的,這是有道理的。謝謝! – brumbrum