[英]libGDX : Drawable from Image can't change its color
When I get Drawable
from Image
from one white pixel (1×1) Texture
, its work fine, but I can't change its color. 当我从一个白色像素(1×1) Texture
从Image
获得Drawable
,它的工作正常,但是我无法更改其颜色。 Why? 为什么?
public static Drawable getDrawable(Texture texture, Color color) {
Image image = new Image(texture);
image.setColor(color);
return image.getDrawable();
}
When I call it: 当我称它为:
// can't change color!! ==> still white (default)
getDrawable(pixel, new Color(0, 1f, 0, 0.5f));
Anyone Can advice me :). 任何人都可以建议我:)。
The only Drawable types that support having their own color are SpriteDrawable and NinePatchDrawable, and that is because they wrap Sprites and NinePatches, which both have color parameters. 唯一支持具有自己颜色的Drawable类型是SpriteDrawable和NinePatchDrawable,这是因为它们包装了都有颜色参数的Sprites和NinePatches。
public static Drawable getTintedDrawable(Texture texture, Color color) {
Sprite sprite = new Sprite(texture);
sprite.setColor(color);
return new SpriteDrawable(sprite);
}
If you have an existing TextureRegionDrawable or NinePatchDrawable, you can call tint()
on it to generate a new Drawable instance with the color you want. 如果您已有一个TextureRegionDrawable或NinePatchDrawable,则可以在其上调用tint()
以生成具有所需颜色的新Drawable实例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.