scene2d button scaling with libgdx(使用 libgdx 进行scene2d 按钮缩放)
问题描述
我不知道是不是只有我一个人,但 drawables 让我感到困惑.他们是打算保持给定的大小,还是有办法在其中缩放图像?我知道他们可以使用 Ninepatch 通过拉伸图像来填充某些区域,但我想缩放它拉伸的图像.我正在使用 TextButton对于我的菜单按钮,但它们太大了,我很想知道如何缩放它们.我正在从地图集中检索皮肤,其中包含九个补丁图像.这是设置屏幕:这是我正在使用的包中的图像:下面是 TextureAtlas 和 Skin 的初始化:
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);
作为最后的手段,我想我可以尝试创建自己的可以缩放的文本按钮 actor,感谢您抽出宝贵时间.
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);
这篇关于使用 libgdx 进行scene2d 按钮缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 libgdx 进行scene2d 按钮缩放
基础教程推荐
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01