简体   繁体   English

LibGDX:让舞台上的所有演员都不受限制

[英]LibGDX: Make all actors on a stage unchecked

I have a stage with multiple buttons on it that basically serves as a toolbox. 我有一个带有多个按钮的舞台,它基本上用作工具箱。 I want the user to be able to select between the different items that are displayed; 我希望用户能够在显示的不同项目之间进行选择; therefore when the user selects one item, all others have to be deselected. 因此,当用户选择一个项目时,必须取消选择所有其他项目。

I thought of doing that with the checked property of libGDX buttons. 我想用libGDX按钮的checked属性来做这件事。 However, I don't know how to programatically uncheck a button and to acces all actors on a stage in the simplest possible way. 但是,我不知道如何以编程方式取消选中按钮并以最简单的方式访问舞台上的所有演员。

I can't provide code becuase as I said, I don't even know how tp uncheck a button and google doesn't help. 我不能提供代码,因为我说,我甚至不知道如何取消选中一个按钮和谷歌没有帮助。 Is that even possible? 这甚至可能吗? If not, I'd be happy about other suggestions. 如果没有,我会对其他建议感到高兴。

Take a look at a ButtonGroup 看一下ButtonGroup

ButtonGroup is not an actor and has no visuals. ButtonGroup不是actor,也没有视觉效果。 Buttons are added to it and it enforce a minimum and maximum number of checked buttons. 按钮被添加到它,它强制执行最小和最大数量的选中按钮。 This allows for buttons (button, text button, checkbox, etc) to be used as "radio" buttons. 这允许按钮(按钮,文本按钮,复选框等)用作“无线电”按钮。 https://github.com/libgdx/libgdx/wiki/Scene2d.ui#wiki-ButtonGroup https://github.com/libgdx/libgdx/wiki/Scene2d.ui#wiki-ButtonGroup

Also try and take a look at the useful javadocs for it http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/ButtonGroup.html 另请尝试查看有用的javadocs http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/ButtonGroup.html

Basically you create your ButtonGroup add actors and set a minimum amount of checked things that should be allowed. 基本上,您创建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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM