Libgdx如何实现选中按钮列表?

时间:2014-07-06 15:16:16

标签: java user-interface libgdx scene2d

如何实现水平对齐按钮列表,其中一次只能检查一个按钮?我想为一个游戏实现这个目的,你必须从列表中选择工具并单击一个对象来执行一个动作。我想突出显示代表当前工具的按钮,以及何时选择另一个按钮将前一个返回到非突出显示状态,以及选择突出显示状态的按钮。因此,在任何给定时刻只能有一个工具处于活动状态,并且在您使用该工具并且没有选择其他内容之后,应该没有突出显示的按钮。我过去两天尝试过自己实施,但我无法做到。我想也许在libgdx scene2d中有这样的东西,但我找不到任何东西。任何帮助或建议将不胜感激。

2 个答案:

答案 0 :(得分:5)

听起来像是ButtonGroup的工作。在基本的谷歌搜索之后,我没有意外地表现出来。

请在此处查看答案:LibGDX: Make all actors on a stage unchecked

//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.

答案 1 :(得分:2)

使用ButtonGroup让选择正常工作就像Kevin Workman所说。要水平布置按钮,请使用基本表格或水平组。要使突出显示工作,您可以使用libgdx UI工具包的ImageButton类,并使用您的普通图像来检查按钮的状态。对于未经检查的状态,您只需用浅灰色调色。请参阅libgdx中皮肤的用法以供进一步参考。 https://github.com/libgdx/libgdx/wiki/Skin

相关问题