我試圖使用Nine Patch作爲Libgdx Scene2d UI按鈕的背景。它正在加載,但它真的很醜。我可以看到「元數據」的像素,並且如果它只是一個普通的圖像被拉伸(按鈕上的文字是「繼續」):將9-patch圖像作爲Libgdx Scene2d加載按鈕背景看起來很糟糕
我加載了.9.png
通過(libgdx)文件直接導入(libgdx)NinePatchDrawable
NinePatch
這樣的:
this.dialogButtonUp = new NinePatchDrawable(
new NinePatch(new Texture(Gdx.files.internal("data/button-round.9.png"))));
this.dialogButtonDown = new NinePatchDrawable(
new NinePatch(new Texture(Gdx.files.internal("data/button-round-down.9.png"))));
然後我做一個TextButtonStyle
描述按鈕,並引用兩個NinePatch
繪項目:
TextButton.TextButtonStyle buttonStyle = new TextButton.TextButtonStyle();
buttonStyle.font = aValidFontReally;
buttonStyle.fontColor = Color.BLACK;
buttonStyle.up = this.dialogButtonUp;
buttonStyle.down = this.dialogButtonDown;
buttonStyle.pressedOffsetX = -2;
我間接地建立按鈕,通過Dialog
箱:
new Dialog(...).button("Continue", null, buttonStyle);
我已檢查.9.png
文件,以確保:
- 該資產的文件是在刷新Eclipse
- 元數據邊界像素是完全不可見的或完全可見的黑色
- 表示Android
draw9patch
工具可以加載圖像並驗證它們
有關要檢查或更改什麼的其他建議?
嘗試使用NinePatch.draw()與SpriteBatch一起繪製每個NinePatch作爲至少會隔離問題的出處,即如果問題出現,那麼問題不在於NinePatch。 – 2013-03-12 12:41:51
好點!我只是試了一下,並用直接的'NinePatch.draw(...)'看到了同樣的醜陋。所以'對話框'和'按鈕'不是在拼湊它。 – 2013-03-12 19:09:22
看看NinePatch的源代碼(https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g2d/NinePatch.java)我不認爲它的確如此你使用帶有一個Texture參數的構造函數。嘗試使用這個構造函數:public NinePatch(Texture texture,int left,int right,int top,int bottom) – 2013-03-12 20:12:01