动画无法正确呈现
animation does not render properly
我正在使用以下代码渲染在另一个 class 中创建的精灵:
batch = new SpriteBatch();
textureAtlas = new TextureAtlas(Gdx.files.internal("bird.atlas"));
animation = new Animation(1/6f, textureAtlas.getRegions());
我的问题是它没有 运行 不同的图像,我得到的是静态图像。如果我将动画速度更改为 1/10000f,它会疯狂地翻转图像。
这是小鸟class中render方法中的代码,然后我运行renderer.render();来自游戏 class.
batch.begin();
elapsedTime = Gdx.graphics.getDeltaTime();
batch.draw(animation.getKeyFrame(elapsedTime, true), 50, 50);
batch.end();
这会在我的平铺地图上显示我的鸟,但是这只鸟不会拍打翅膀:( 非常难过。
libgdx版本:1.5.5
关于我误入歧途的任何想法?
动画需要经过的时间,而不是增量时间。您的 elapsedTime
变量仅存储增量时间。
将 elapsedTime = Gdx.graphics.getDeltaTime();
更改为 elapsedTime += Gdx.graphics.getDeltaTime();
。
我正在使用以下代码渲染在另一个 class 中创建的精灵:
batch = new SpriteBatch();
textureAtlas = new TextureAtlas(Gdx.files.internal("bird.atlas"));
animation = new Animation(1/6f, textureAtlas.getRegions());
我的问题是它没有 运行 不同的图像,我得到的是静态图像。如果我将动画速度更改为 1/10000f,它会疯狂地翻转图像。
这是小鸟class中render方法中的代码,然后我运行renderer.render();来自游戏 class.
batch.begin();
elapsedTime = Gdx.graphics.getDeltaTime();
batch.draw(animation.getKeyFrame(elapsedTime, true), 50, 50);
batch.end();
这会在我的平铺地图上显示我的鸟,但是这只鸟不会拍打翅膀:( 非常难过。
libgdx版本:1.5.5
关于我误入歧途的任何想法?
动画需要经过的时间,而不是增量时间。您的 elapsedTime
变量仅存储增量时间。
将 elapsedTime = Gdx.graphics.getDeltaTime();
更改为 elapsedTime += Gdx.graphics.getDeltaTime();
。