我有一个应该像加载栏一样的精灵。我通过使用像9patch类型(http://cdn.dibbus.com/wp-content/uploads/2011/03/btn_black.9.png)创建的示例图像尝试了这一点。它在开始时似乎没问题,但随着精灵的宽度增加,精灵开始看起来像pixeled。任何人都知道问题可能是什么,或者有任何解决方案?代码如下所示。
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);
}
答案 0 :(得分:4)
不要使用精灵来拉伸它。我推荐一个来自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)