androidlibgdxspriterendersizing

libgdx how to get image to take up the whole screen?


I have this image(https://i.sstatic.net/ucafS.jpg) and am trying to make it take up the whole screen. Heres my code

static Texture img;
static Sprite sprite;
public static void load(){

    img = new Texture(Gdx.files.internal("menu/stick.PNG"));
    //libgdx scales it , it wont mess up
    img.setFilter(TextureFilter.Linear, TextureFilter.Linear);

    sprite = new Sprite(img);
    sprite.flip(false, true);
    sprite.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}

The output still doesnt show the stick figure taking up the whole screen. Output:https://i.sstatic.net/kGTfV.jpg

Am i going about this the wrong way? I thought by setting the sprite(the object rendering the image to the screen) to the size of the screen, the image should take up the whole screen as well.


Solution

  • Something like this should work:

        batch.draw(sprite.getTexture(), x, y, sprite.getWidth(), sprite.getHeight());