And*_*rew 7 java user-interface libgdx scene2d
如何实现水平对齐按钮列表,其中一次只能检查一个按钮?我想为一个游戏实现这个目的,你必须从列表中选择工具并单击一个对象来执行一个动作.我想突出显示代表当前工具的按钮,以及当您选择另一个按钮以将前一个返回到非突出显示状态时以及已选择为突出显示状态的按钮时.因此,在任何给定时刻只能有一个工具处于活动状态,并且在您使用该工具并且未选择其他内容之后,应该没有突出显示的按钮.我过去两天尝试过自己实施,但我做不到.我想也许在libgdx scene2d中有这样的东西,但我没有找到任何东西.任何帮助或建议将不胜感激.
听起来像是ButtonGroup的工作.我很惊讶在基本的谷歌搜索后没有出现.
请参阅此处的答案:LibGDX:使舞台上的所有演员都不受限制
//initalize stage and all your buttons
ButtonGroup buttonGroup = new ButtonGroup(button1, button2, button3, etc...)
//next set the max and min amount to be checked
buttonGroup.setMaxCheckCount(1);
buttonGroup.setMinCheckCount(0);
//it may be useful to use this method:
setUncheckLast(true); //If true, when the maximum number of buttons are checked and an additional button is checked, the last button to be checked is unchecked so that the maximum is not exceeded.
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2612 次 |
最近记录: |