英文:
Libgdx center Scaled Textbutton in HorizontalGroup
问题
将TextButtons放入HorizontalGroup中,然后对它们进行缩放会导致视图失真,即使采用了居中对齐。
add_button = new TextButton("+", textButtonStyle);
add_button.setTransform(true);
add_button.setScale(0.7f);
add_button.setDebug(true);
remove_button = new TextButton("-", textButtonStyle);
remove_button.setTransform(true);
remove_button.setScale(0.7f);
remove_button.setDebug(true);
HorizontalGroup brush_op_group = new HorizontalGroup();
brush_op_group.addActor(remove_button);
brush_op_group.addActor(add_button);
brush_op_group.setDebug(true);
这将导致如下图像:
似乎按钮的位置是基于它们未缩放大小计算的。
如何纠正这个问题?
英文:
Putting TextBttons into a HorizontalGroup, then scaling them results in a distorted view, even with centered alignment.
add_button = new TextButton("+",textButtonStyle);
add_button.setTransform(true);
add_button.setScale(0.7f);
add_button.setDebug(true);
remove_button = new TextButton("-",textButtonStyle);
remove_button.setTransform(true);
remove_button.setScale(0.7f);
remove_button.setDebug(true);
HorizontalGroup brush_op_group = new HorizontalGroup();
brush_op_group.addActor(remove_button);
brush_op_group.addActor(add_button);
brush_op_group.setDebug(true);
which results in the below image:
It seems like the buttons positions are calculated based on their unscaled sizes.
How can this be corrected?
答案1
得分: 0
以下是翻译好的部分:
add_button = new TextButton("+", textButtonStyle);
add_button.setTransform(true);
add_button.setOrigin(Align.left | Align.top);
add_button.setScale(0.8f);
remove_button = new TextButton("-", textButtonStyle);
remove_button.setTransform(true);
remove_button.setOrigin(Align.right | Align.top);
remove_button.setScale(0.8f);
HorizontalGroup file_op_group = new HorizontalGroup();
Table brush_op_group = new Table().center();
brush_op_group.add(remove_button).right();
brush_op_group.add(add_button).left();
brush_op_group.setDebug(true);
运作得很好!
英文:
For this purpose I ended up using tables:
add_button = new TextButton("+",textButtonStyle);
add_button.setTransform(true);
add_button.setOrigin(Align.left | Align.top);
add_button.setScale(0.8f);
remove_button = new TextButton("-",textButtonStyle);
remove_button.setTransform(true);
remove_button.setOrigin(Align.right | Align.top);
remove_button.setScale(0.8f);
HorizontalGroup file_op_group = new HorizontalGroup();
Table brush_op_group = new Table().center();
brush_op_group.add(remove_button).right();
brush_op_group.add(add_button).left();
brush_op_group.setDebug(true);
Works like a charm!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论