加载九个补丁图像作为Libgdx Scene2d按钮背景看起来很糟糕
我正在尝试使用Nine Patch作为Libgdx Scene2d UI按钮的背景。 这是装载,但它真的很难看。 我可以看到“元数据”像素,它被拉伸就好像它只是一个普通的图像(按钮上的文字是“继续”):
我正在通过(libgdx) NinePatch
将.9.png
文件直接加载到(libgdx) 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
drawable:
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
工具可以加载图像并validation它们
关于检查或更改内容的任何其他建议?
感谢来自@RodHyde的一些指针,看起来libgdx NinePatch
类被设计为接受“后处理”的九个补丁纹理(即,使用单独的整数值来描述如何将单个纹理切割成补丁)。 这种“处理”通常是将“.9.png”文件打包到TextureAtlas
(请参阅http://sofzh.miximages.com/java/Texture-packer”文件:
private static NinePatch processNinePatchFile(String fname) { final Texture t = new Texture(Gdx.files.internal(fname)); final int width = t.getWidth() - 2; final int height = t.getHeight() - 2; return new NinePatch(new TextureRegion(t, 1, 1, width, height), 3, 3, 3, 3); }
这会加载纹理,创建一个修剪掉1像素元数据边框的子区域,然后猜测九个补丁边框元素是3像素宽/高。 (通过在纹理数据中进行正确计算可能是正确的,但不值得付出努力 – 在这种情况下只需将纹理放在图册中。)
- 何时使用静态方法和字段?
- 如何序列化ArrayList 2x并且不要过度编写已经存在的ArrayList JAVA
- 抛出exception时EDT是否重启?
- 无法获得在Spring Security中使用的@Secured Method Security注释
- 写入通道后,Java Selector返回带有OP_READ的SelectionKey,而无需在无限循环中的数据
- Java和Maven构建器如何在eclipse中协同工作?
- Spring Security:抛出LockedException而不是BadCredentialsException,为什么?
- 从Java获得有效的屏幕大小
- mailR Connection拒绝来自linux而不是来自windows