java - LibGDX:根据单词的长度在屏幕上创建文本按钮的数量?
问题描述
我正在考虑一种类似 4 Pics 1 Word-like 的游戏回答方法,其中有一个空白并显示一组字符供玩家单击以输入可能的答案。我只是在想如何使显示的文本按钮的数量与单词的字符数量(单词的长度)相同?
解决方案
// 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);
推荐阅读
- ruby-on-rails - 0:Fixnum Prawn/Rails 的未定义方法“删除”
- asp.net - 使用 Windows 身份验证时会话超时是否可行?
- c++ - 将 std::regex 设为静态是个好主意吗?
- amazon-web-services - 如何加快两个帐户之间的文件复制速度
- python - 如何遍历带有嵌套字典的列表?
- reporting-services - 在参数 ssrs(rdl) 中将特定值设为默认值
- angularjs - response.redirect() 在 express (NodeJS) 中不起作用
- python - 如何使用 self.myQListWidget.itemSelectionChanged.connect() 获取属于自定义 QListWidgetItem 的 QComboBox 的值?
- python - 在 sqlalchemy 中对关系使用混合属性
- c - 这个推理我哪里错了?