当setSize调用过多次时,9patch看起来像像素一样



我有一个精灵,它的作用应该像加载条。我使用了一个像9patch类型一样创建的示例图像来尝试这一点(http://cdn.dibbus.com/wp-content/uploads/2011/03/btn_black.9.png)。一开始看起来还可以,但随着精灵宽度的增加,精灵开始看起来像像素化了。有人知道问题可能是什么,或者有什么解决方案吗?代码如下所示。

public Sprite loaded;
public void init()
{
        atlas = new TextureAtlas(Gdx.files.
                 internal("data/misc/menu_button.pack"));
        loaded =  atlas.createSprite("loadbar");
        loaded.setPosition((Misc.WIDTH/2) - unloaded.getWidth()/2,
             Misc.HEIGTH - unloaded.getHeight());
}
public void draw_load_bar() //render function
{
    if(loaded.getWidth() < 600)
    {
        loaded.setSize(loaded.getWidth()+ 0.5f, loaded.getHeight());
    }
    loaded.draw(batch);
}

不要用Sprite来拉伸它。我推荐一个来自libgdx的真正的Ninepatch。

public NinePatch loaded;
private float posX, posY, width, height;
    public void init()
    {
            loaded =  new NinePatch(the Texture here,10, 10, 10, 10); //bounds outside
    //set right pos here...
    }
    public void draw_load_bar(SpriteBatch batch) //render function
    {
        if(loaded.getWidth() < 600)
        {
           //update the size of it here (guess pos is static)
           width++;
        }
    //need to parse the batch and the right sizes.
        loaded.draw(batch, posx, posy, width, height);
    }

之后,你可以像精灵或纹理一样处理它,但它确实很好,没有问题。如果你想拉伸整个图片,只需在创建new NinePatch(texture, 0,0,0,0) 时设置任何边界即可

相关内容

最新更新