使用 libgdx 更新每一帧动画位置的属性方式是什么?



我只需要知道用Animation类和libgdx改变框架位置的最佳方法:

我用许多TextureRegions制作一个Animation对象,我找到了这个解决方案来更新渲染方法中帧的位置:

batch.begin();
if (currentFrame.equals(tex1))
    batch.draw(currentFrame, w, h,120,160); 
else if (currentFrame.equals(tex2))
    batch.draw(currentFrame, w+5, h+10,120,160);
    batch.end();

这将在不同的位置按顺序绘制每一帧动画;这是一个好的解决方案,还是存在更好的解决方案?谢谢。

初始化动画对象后,只需使用getKeyFrame方法获取当前帧并使用batch:

绘制它
TextureRegion currentFrame = animation.getKeyFrame(Gdx.graphics.getDeltaTime(), true);
batch.draw(currentFrame, 0, 0);

最新更新