I was thinking of a 4 Pics 1 Word-like answering method for a game, where there is a blank and a set of characters are displayed for the player to click to type in the possible answer. I was just thinking how can you make the amount of textbutton shown is same to the amount of character of a word (length of a word)?
Asked
Active
Viewed 34 times
1 Answers
0
// 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);
You also can use Table for the task, it should calculate size itself
Table table = new Table();
TextButton textButton = new TextButton(yourWord, skin);
table.add(textButton);

ramazan
- 66
- 3