LibGDX:使舞台上的所有演员取消选中状态

3
我有一个包含多个按钮的舞台,基本上可以作为工具箱。我希望用户能够在显示的不同项之间进行选择。因此,当用户选择一项时,所有其他项都必须取消选择。
我考虑使用libGDX按钮的选中属性来实现这个功能。然而,我不知道如何编程取消选中一个按钮以及以尽可能简单的方式访问舞台上的所有演员。
我无法提供代码,因为就像我说的那样,我甚至不知道如何取消选中一个按钮,而且谷歌也没有帮助。这是否可能?如果不是,我会很高兴听取其他建议。
1个回答

4

看一下ButtonGroup

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并添加演员,设置应允许的最小选中数量。

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接