android - LibGDX - 以固定比例缩放图像

标签 android layout libgdx

我的 LibGDX 游戏有一个带有 Logo 和一些按钮的开始屏幕。我不知道如何以固定比例缩放 Logo 而不扭曲它。

这是代码:

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

最佳答案

我发现您可以将它用于图像 - 效果很好!

imageLogo.setScaling(Scaling.fit);

关于android - LibGDX - 以固定比例缩放图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25514428/

相关文章:

android - Kotlin 泛型抽象类

python - reportlab - 无法将物理打印页面的上边距设置为零

css - 文本在 2 列布局中被截断

gridview - Flutter 混合布局 - 带行的网格

java - LibGDX 游戏突然卡顿了?

java - stage.act() 上的 NullPointerException

java - libGDX spiriteBatch.draw() 没有定位在正确的位置

android - Xamarin.Android 支持库

android - 安卓一指缩放+旋转

libgdx - 如何将数据从 Pixmap 写入 Framebuffer 的深度缓冲区?