简体   繁体   中英

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

This would do the trick:

img.setFillParent(true);

Reference: Widget#setFillParent

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM