Question

I have a sprite that is supposed to act like a loadbar. I have tried this by using an example image that has been created like a 9patch-type (http://cdn.dibbus.com/wp-content/uploads/2011/03/btn_black.9.png). It seems okay in the start, but as the width of the sprite increases the sprite starts to look pixeled. Anyone know what the problem could be, or have any solution? The code is shown below.

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);
}
Was it helpful?

Solution

Dont use a Sprite to stretch it. I'd recommend a real Ninepatch from libgdx for it.

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);
    }

after that you can handle it like a Sprite or Texture but it does stratch right without issues. If you want to the full Picture to be Stretched simply do net set any bounds at the creation new NinePatch(texture, 0,0,0,0)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top