libgdx- changing the sprite texture with animation

Viewed 6716

I am using the animation class to make a simple animation, with only 2 frames. With animation, i can get the index, or texture region at the current time.

if (!animation.isAnimationFinished(time))
    time += Gdx.graphics.getDeltaTime();
else
    time = 0;

But the problem is, that I can't load any texture, its width and height must be a power of 2, so i got a big 1024x1024 texture, that has the 2 images. With sprite.setTexture() i can only put a Texture, but animation.getframe returns a texture region.

Is there a way to change the sprite texture with an animation?

Also

 sprite.setTexture(animation.getKeyFrame(time).getTexture());

Does not work.

This works

sprite = new Sprite(animation.getKeyFrame(time));

But I don't think is the best idea... I think is slow can can make bugs.

1 Answers
Related