【问题标题】:LibGDX: Creating a the amount of textbutton on a screen depending on the length of a word?LibGDX:根据单词的长度在屏幕上创建文本按钮的数量?
【发布时间】:2020-01-20 16:03:37
【问题描述】:

我正在考虑一种类似 4 Pics 1 Word-like 的游戏回答方法,其中有一个空白并显示一组字符供玩家单击以输入可能的答案。我只是在想如何使显示的文本按钮的数量与单词的字符数量(单词的长度)相同?

【问题讨论】:

    标签: java libgdx game-development


    【解决方案1】:

    related to get width

    // for BitmapFont API < 1.5.6
    float width = font.getBounds(yourWord).width;
    float edgeWidth = 5f; // indention 
    yourTextButton.setWidth(width + 2 * edgeWidth);
    
    // for BitmapFont API >= 1.5.6
    GlyphLayout layout = new GlyphLayout();
    layout.setText(yourWord);
    float width = layout.width;
    float edgeWidth = 5f; // indention 
    yourTextButton.setWidth(width + 2 * edgeWidth);
    

    您也可以将Table 用于任务,它应该自己计算大小

    Table table = new Table();
    TextButton textButton = new TextButton(yourWord, skin);
    table.add(textButton);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-11
      • 1970-01-01
      • 1970-01-01
      • 2016-12-20
      • 2019-07-15
      • 2012-06-17
      • 2016-08-28
      相关资源
      最近更新 更多