libgdx - 创建一个九点

时间:2014-07-19 09:36:40

标签: java android libgdx nine-patch

我正在读书 https://github.com/libgdx/libgdx/wiki/Ninepatches

我的形象 enter image description here

toast_patch = new NinePatch(texture, 10, 10, 10, 10);

输出:

enter image description here

我只是得到了优势...... (忽略文字) 我该怎么办?

3 个答案:

答案 0 :(得分:1)

使用此图片作为指导。我在你的问题上使用了你的形象。

enter image description here

答案 1 :(得分:1)

您正在使用纹理的全宽度作为“角落”,因此没有像素可以拉伸到按钮的边缘或“中间”。一个“九个补丁”应该有九个补丁。你已经将纹理分成了四个部分(四个角),其他五个部分没有纹理数据。尝试:

toast_patch = new NinePatch(texture, 7, 7, 7, 7);

(或者任何沿着一个轴不总和为20的东西。第一个参数是左边缘像素的数量,第二个是右边缘像素的数量,隐含地任何剩余像素用于'中间'section。同样适用于顶部和底部。)

答案 2 :(得分:0)

   graySkin = new Skin()
   grayAtlas = new TextureAtlas(Gdx.files.internal("ui/gray.pack"));
   grayAtlas.createPatch("patch");
   graySkin.addRegions(grayAtlas);
   grayButtonStyle = new TextButton.TextButtonStyle();
   grayButtonStyle.font = fontB44;
   grayButtonStyle.up = graySkin.getDrawable("patch");

    //gray.pack
    gray.9.png
    format: RGBA8888
    filter: Nearest,Nearest
    repeat: none
    patch
      rotate: false
      xy: 1, 1
      size: 100, 100
      split: 17, 17, 19, 19
      orig: 100, 100
      offset: 0, 0
      index: -1

my gray button