user2246120
user2246120

Reputation: 1505

libgdx stage doesn't draw stretched image

I'm using libgdx' stage to draw a background. The background image should stretch to fit all sizes of phones and tablets. But the image is only displayed as a small image and doesn't stretch. Any ideas why?

@Override
public void show() {
      stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
      batch = new SpriteBatch();
      Assets.load();
      Image img = new Image(new TextureRegion(Assets.background));
      stage.addActor(img);  
      Table table = new Table(skin);
      stage.addActor(table);
}

@Override
public void render(float delta) {
     Gdx.gl.glClearColor(1, 1, 1, 1);
     Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
     stage.act(delta);
     stage.draw();  
}

@Override
public void resize(int width, int height) {
    stage.setViewport(width, height, true);
}

Upvotes: 1

Views: 2088

Answers (1)

Daahrien
Daahrien

Reputation: 10320

This would do the trick:

img.setFillParent(true);

Reference: Widget#setFillParent

Upvotes: 4

Related Questions