【发布时间】:2015-12-10 13:55:03
【问题描述】:
我正在关注一本 libgdx 书籍。在其中,作者使用 Animation 类来播放动画。这是相关代码:
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 返回正确的纹理区域至关重要。我想这与一直循环播放相同的动画有关。我可以要求对此主题进行更多解释吗?
【问题讨论】: