LibGDX:取消检查舞台上的所有演员



我有一个舞台,上面有多个按钮,基本上可以用作工具箱。我希望用户能够在显示的不同项目之间进行选择;因此,当用户选择一个项目时,必须取消选择所有其他项目。

我想用libGDX按钮的检查属性来做到这一点。但是,我不知道如何以编程方式取消选中按钮并以最简单的方式访问舞台上的所有演员。

无法提供代码,因为正如我所说,我什至不知道如何取消选中按钮,谷歌也无济于事。这可能吗?如果没有,我会很高兴其他建议。

看看一个按钮组

ButtonGroup不是演员,也没有视觉效果。按钮被添加到其中,并强制执行最小和最大数量的选中按钮。这允许将按钮(按钮、文本按钮、复选框等)用作"单选"按钮。https://github.com/libgdx/libgdx/wiki/Scene2d.ui#wiki-ButtonGroup

还可以尝试查看有用的javadocs http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/ButtonGroup.html

基本上,您创建ButtonGroup添加Actor并设置应允许的最小数量的检查内容。

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

最新更新