How can I change the texture in a Scene2D Image?
http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/Image.html
There is no such method in the docs. I create mine by providing its constructor a texture reference.
You have to change the drawable and wrap your new texture in a SpriteDrawable
Texture texture = ...;
Image image = new Image(texture);
// switch to a new texture
Texture newTexture = ...;
image.setDrawable(new SpriteDrawable(new Sprite(newTexture)));
You can use:
Texture texture = ...;
Image image = new Image(texture);
// change to a new texture
Texture newTexture = ...;
image.setDrawable(new TextureRegionDrawable(new TextureRegion(newTexture)));
Without use SpriteDrawable or create new Sprite instances.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With