scene2d键缩放与libgdx [英] scene2d button scaling with libgdx
问题描述
我不知道这是否只是我,但<一个href="http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/utils/Drawable.html"相对=nofollow>可绘制我迷惑。难道他们打算继续给他们的大小,或者是有没有办法在其中缩放图像?据我所知,他们可以用ninepatch通过拉伸图像,以填补某些领域,但我想它延伸到缩放图像。我使用的是<一href="http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/TextButton.html"相对=nofollow> TEXT按钮 我的菜单按钮,但他们是太大了,我很想知道如何去衡量他们。我从检索一本地图册,其中有ninepatch图像,它的皮肤。 下面是设置界面: 下面是我使用的是包中的图片: 这里是TextureAtlas的初始化,和皮肤:
I don't know if it is just me, but drawables confuse me. Are they intended to keep the size they are given, or is there a way to scale the image within them? I understand they can use ninepatch to fill certain areas by stretching an image, but I want to scale the image that it stretches. I am using a TextButton for my menu buttons, but they are way too big, and I would love to know how to scale them. I am retrieving the skin from an atlas, which has ninepatch images in it. Here is the settings screen: Here are the images in the pack I am using: Here is the initialization of the TextureAtlas, and Skin:
buttonAtlas = new TextureAtlas(Gdx.files.internal("buttons/buttons.pack"));
buttonSkin = new Skin(buttonAtlas);
下面是菜单按钮的初始化。
Here is the initialization of that menu button.
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);
}
});
也许我可以改变我如何把它放在桌子上,或如何我在舞台上把表?
And perhaps I could change how I put it in the table, or how I put the table in the stage?
table.add(buttonMenu).width(Gdx.graphics.getWidth()/4);
stage.addActor(table);
作为最后的手段,我想我可以尝试创建我自己的文字按钮的演员,我可以扩展,感谢您的时间。
As a last resort I suppose I could attempt creating my own text button actor that I could scale, thank you for your time.
推荐答案
首先,如果你知道你的图片过大:最好的办法是缩放图像本身,以更小的尺寸,然后用TexturePacker也产生新TextureAtlas包含更小的图像。
First of all if you know that your images are too big: The best would be to scale the images themselves to a smaller size and then use the TexturePacker too generate a new TextureAtlas that contain the smaller images.
总之,你可以将图像缩放按钮,用TableLayout,如果你真的想,看到的例子:
Anyhow you can scale the image button with the TableLayout if you really want to, see example:
table.add(buttonMenu).width(100).height(100);
这篇关于scene2d键缩放与libgdx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!