【发布时间】:2014-02-01 07:09:58
【问题描述】:
如何更改 Scene2D 图像中的纹理?
http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/Image.html
文档中没有这种方法。我通过为其构造函数提供纹理参考来创建我的。
【问题讨论】:
标签: libgdx
如何更改 Scene2D 图像中的纹理?
http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/Image.html
文档中没有这种方法。我通过为其构造函数提供纹理参考来创建我的。
【问题讨论】:
标签: libgdx
您必须更改可绘制对象并将新纹理包装在 SpriteDrawable 中
Texture texture = ...;
Image image = new Image(texture);
// switch to a new texture
Texture newTexture = ...;
image.setDrawable(new SpriteDrawable(new Sprite(newTexture)));
【讨论】:
((SpriteDrawable)image.getDrawable()).getSprite().setTexture(newTexture); 是否也能正常工作?
Image 类创建一个.setTexture 函数。
setTextureRegion,一个setSprite,也许还有一个setPixmap,然后......你明白我的意思了。
你可以使用:
Texture texture = ...;
Image image = new Image(texture);
// change to a new texture
Texture newTexture = ...;
image.setDrawable(new TextureRegionDrawable(new TextureRegion(newTexture)));
不使用 SpriteDrawable 或创建新的 Sprite 实例。
【讨论】: