【发布时间】:2020-01-20 16:03:37
【问题描述】:
我正在考虑一种类似 4 Pics 1 Word-like 的游戏回答方法,其中有一个空白并显示一组字符供玩家单击以输入可能的答案。我只是在想如何使显示的文本按钮的数量与单词的字符数量(单词的长度)相同?
【问题讨论】:
标签: java libgdx game-development
我正在考虑一种类似 4 Pics 1 Word-like 的游戏回答方法,其中有一个空白并显示一组字符供玩家单击以输入可能的答案。我只是在想如何使显示的文本按钮的数量与单词的字符数量(单词的长度)相同?
【问题讨论】:
标签: java libgdx game-development
// 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);
【讨论】: