2017-08-31 129 views
0

我想知道是否有可能在LibGDX中爲紋理賦予形狀。LibGDX - 圓形紋理

特別是,我有一個紋理,我想製作一個按鈕。爲此,我想給它一個圓角的形狀。

概括地說,我有這樣的:

enter image description here

,我想這一點:

enter image description here

我已經閱讀過任何明確的答案有些類似的問題。有沒有人遇到這個問題,並找到了一個聰明的解決方案?

+3

的紋理始終是一個矩形,但你可以把透明的源圖像(Alpha通道),並具有調開啓(SpriteBatch)繪製它讓你描述的效果。我認爲這是如此基礎以至於每個人都知道這一點是理所當然的,所以在任何文檔或教程中都沒有提到它。 – Tenfour04

+0

我當然知道 - .- –

+0

我想知道我是否可以動態地做到這一點!因爲我需要爲其他用戶使用矩形圖像,但我需要將其舍入爲菜單 –

回答

0

使用波紋管方法創建圓角紋理圖像,然後向其添加文本。

public static Texture createPixmapRoundCornerRect(Color color, int width, 
      int height, int radius) { 
     Pixmap pixmap = new Pixmap(width, height, Format.RGBA8888); 
     pixmap.setColor(color); 
     pixmap.fillCircle(radius, radius, radius); 
     pixmap.fillCircle(width - radius, radius, radius); 
     pixmap.fillCircle(width - radius, height - radius, radius); 
     pixmap.fillCircle(radius, height - radius, radius); 
     pixmap.fillRectangle(0, radius, width, height - (radius * 2)); 

     pixmap.fillRectangle(radius, 0, width - (radius * 2), height); 
     Texture pixmaptex = new Texture(pixmap); 
     pixmap.dispose(); 
     return pixmaptex; 
    } 
0

這已經回答here。你必須實現你自己的紋理,它使用多邊形來實現你想要做的。