Reputation: 123
I have a valid animation called diceAnimation
from a valid TextureAtlas
called dice
that has several frames in it. What I have an issue with is rendering it. I use the code below to render the animation but it only shows the first frame. If I set timeElapsed
to add one every time instead of using the delta time, it animates but REALLY FAST, ignoring the frames per second defined in the construction. Anyone have ideas?
int elapsedTime;
@Override
public void create() {
batch = new SpriteBatch();
dice = new TextureAtlas("textures/dice/dice.atlas");
diceAnimation = new Animation<TextureRegion>(0.033f, dice.findRegions("one"), PlayMode.LOOP);
}
// ...
@Override
public void render () {
elapsedTime += Gdx.graphics.getDeltaTime();
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(diceAnimation.getKeyFrame(elapsedTime, true), 100, 100);
batch.end();
}
Upvotes: 0
Views: 249
Reputation: 20140
data type of int elapsedTime
should be float instead of int.
OFF_TOPIC
PlayMode.LOOP
is PlayMode
of diceAnimation so you can use
batch.draw(diceAnimation.getKeyFrame(elapsedTime), 100, 100);
Upvotes: 1