【问题标题】:Textbutton not working and scaling issues文本按钮不起作用和缩放问题
【发布时间】:2018-08-31 17:21:09
【问题描述】:

我已经创建了一个包含按钮的带有 scened2d 的表,但是这些按钮有很多问题。

第一个问题是缩放,每当我尝试设置按钮的高度和高度时,都会出现问题 当我设置它时:

table.add(btn).with(100).height(30);

btnStyle.up.setMinWidth(80);
btnStyle.up.setMinHeight(40);
btnStyle.down.setMinWidth(80);
btnStyle.down.setMinHeight(40);

按钮已正确缩放,但背景表现得很奇怪

但是如果我不设置它们的高度和高度,它们的背景是正常的,但是按钮太大了

第二个问题,按钮不能“工作”,因为我不能点击(没有改变) 这是代码

// style
final Skin skin = new Skin(Gdx.files.internal("skin/glassy-ui.json"));
final BitmapFont font = skin.getFont("font");
final TextButton.TextButtonStyle btnStyle = new TextButton.TextButtonStyle();
btnStyle.font = font;
btnStyle.up = skin.getDrawable("button");
btnStyle.down = skin.getDrawable("button-down");
btnStyle.up.setMinWidth(80);
btnStyle.up.setMinHeight(40);
btnStyle.down.setMinWidth(80);
btnStyle.down.setMinHeight(40);

// buttons
Textbutton btn = new TextButton("some text", btnStyle);

我怎样才能正确缩放我的按钮,什么可能导致按钮停止工作?

(已经有一个关于按钮缩放的问题,但没有太大帮助)

【问题讨论】:

  • 不要设置 minWidth 和 height。设置 prefWidth 和 height。您正在使用的那些暗示着可绘制对象的绘制不可能小于您提供的尺寸,这可能会搞砸它。它没有很好的记录。
  • 按钮上的 setHeight 使它看起来像我提供的屏幕截图,我在任何地方都找不到 setPrefWidth
  • 增加stage.camera的视口

标签: libgdx scene2d


【解决方案1】:

为了获得按钮的点击次数,您必须添加一个 ChangeListener。

您用作按钮背景的资源太大,或者它们的内边距太大。使用Skin Composer 预览您的皮肤。

【讨论】:

    【解决方案2】:

    由于按钮不工作,您还记得在您的舞台上调用 setInputProcessor 吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多