[英]LibGDX: Make all actors on a stage unchecked
我有一个带有多个按钮的舞台,它基本上用作工具箱。 我希望用户能够在显示的不同项目之间进行选择; 因此,当用户选择一个项目时,必须取消选择所有其他项目。
我想用libGDX按钮的checked属性来做这件事。 但是,我不知道如何以编程方式取消选中按钮并以最简单的方式访问舞台上的所有演员。
我不能提供代码,因为我说,我甚至不知道如何取消选中一个按钮和谷歌没有帮助。 这甚至可能吗? 如果没有,我会对其他建议感到高兴。
看一下ButtonGroup
ButtonGroup不是actor,也没有视觉效果。 按钮被添加到它,它强制执行最小和最大数量的选中按钮。 这允许按钮(按钮,文本按钮,复选框等)用作“无线电”按钮。 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:
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.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.