简体   繁体   English

libgdx阶段不绘制拉伸图像

[英]libgdx stage doesn't draw stretched image

I'm using libgdx' stage to draw a background. 我正在使用libgdx'阶段来绘制背景。 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 参考: Widget#setFillParent

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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