gpt4 book ai didi

android - 使用 libgdx 缩放 scene2d 按钮

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:15:04 26 4
gpt4 key购买 nike

我不知道是不是只有我,但是drawables把我弄糊涂了。它们是打算保持给定的尺寸,还是有办法在其中缩放图像?我知道他们可以使用 ninepatch 通过拉伸(stretch)图像来填充某些区域,但我想缩放它拉伸(stretch)的图像。我正在使用 TextButton对于我的菜单按钮,但它们太大了,我很想知道如何缩放它们。我正在从 map 集中检索皮肤,其中有 9-patch 图像。这是设置屏幕: The settings screen这是我正在使用的包中的图像: ninepatch images packed这是 TextureAtlas 和 Skin 的初始化:

buttonAtlas = new TextureAtlas(Gdx.files.internal("buttons/buttons.pack"));
buttonSkin = new Skin(buttonAtlas);

这是该菜单按钮的初始化。

TextButtonStyle textButtonStyle = new TextButtonStyle();
textButtonStyle.up = Assets.buttonSkin.getDrawable("bluebutton");
textButtonStyle.down = Assets.buttonSkin.getDrawable("redbutton");
textButtonStyle.font = font;

buttonMenu = new TextButton("Menu", textButtonStyle);
buttonMenu.pad(20.0f);
buttonMenu.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
game.fade.startFadeOut();
super.clicked(event, x, y);
}
});

也许我可以改变我把它放在 table 上的方式,或者我把 table 放在舞台上的方式?

table.add(buttonMenu).width(Gdx.graphics.getWidth()/4);
stage.addActor(table);

作为最后的手段,我想我可以尝试创建我自己的可以缩放的文本按钮 actor,谢谢您的宝贵时间。

最佳答案

首先,如果您知道您的图像太大:最好的办法是将图像本身缩放到较小的尺寸,然后使用 TexturePacker 生成包含较小图像的新 TextureAtlas。

如果你真的想的话,你可以用 TableLayout 缩放图像按钮,看例子:

table.add(buttonMenu).width(100).height(100);

关于android - 使用 libgdx 缩放 scene2d 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23594611/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com