[英]libGDX : Drawable from Image can't change its color
當我從一個白色像素(1×1) Texture
從Image
獲得Drawable
,它的工作正常,但是我無法更改其顏色。 為什么?
public static Drawable getDrawable(Texture texture, Color color) {
Image image = new Image(texture);
image.setColor(color);
return image.getDrawable();
}
當我稱它為:
// can't change color!! ==> still white (default)
getDrawable(pixel, new Color(0, 1f, 0, 0.5f));
任何人都可以建議我:)。
唯一支持具有自己顏色的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);
}
如果您已有一個TextureRegionDrawable或NinePatchDrawable,則可以在其上調用tint()
以生成具有所需顏色的新Drawable實例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.