Skip to content Skip to sidebar Skip to footer

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 t

Solution 1:

Take a look at a ButtonGroup

ButtonGroup is not an actor and has no visuals. 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

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

Basically you create your ButtonGroup add actors and set a minimum amount of checked things that should be allowed.

//initalize stage and all your buttonsButtonGroupbuttonGroup=newButtonGroup(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.

Post a Comment for "Libgdx: Make All Actors On A Stage Unchecked"