我的LibGDX游戏有一个带有徽标和一些按钮的开始屏幕。我无法弄清楚如何以固定的比例缩放徽标,以免扭曲它。
这就是代码:
public StartScreen(int lastScore, InputListener inputListener) {
super();
this.listener = inputListener;
stage = new Stage();
Gdx.input.setInputProcessor(stage);
Table table = new Table();
table.setFillParent(true);
table.setBackground(new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("background.png")))));
Image imageLogo = new Image();
imageLogo.setDrawable(new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("title.png")))));
// Here's the problem, the image is not scaled correctly...
table.add(imageLogo).center().colspan(2);
table.row();
// Some Buttons
table.add(button1).colspan(2).padBottom(30);
table.row();
table.add(button2).padBottom(30);
table.add(button3).padBottom(30);
table.row();
table.add(button4).colspan(2);
stage.addActor(table);
//table.debug();
}
答案 0 :(得分:6)
我发现你可以将它用于图像 - 工作正常!
imageLogo.setScaling(Scaling.fit);
答案 1 :(得分:-1)
您可以按如下方式缩放图像:
Image imageLogo = new Image();
imageLogo.setDrawable(new TextureRegionDrawable(
new TextureRegion(new Texture(Gdx.files.internal("title.png")))));
// 0.9f scales to 90% of the original height and width
final float heightScaleFactor = 0.9f;
final float widthScaleFactor = 0.9f;
imageLogo.setHeight(imageLogo.getHeight() * heightScaleFactor);
imageLogo.setWidth(imageLogo.getWidth() * widthScaleFactor);