2014-02-07 37 views
2

我有一個舞臺上有多個按鈕,它基本上是一個工具箱。我希望用戶能夠在顯示的不同項目之間進行選擇;因此當用戶選擇一個項目時,所有其他項目都必須被取消選擇。LibGDX:讓舞臺上的所有演員不被檢查

我想這樣做與libGDX按鈕的選中屬性。但是,我不知道如何以編程方式取消選中按鈕並以最簡單的方式訪問舞臺上的所有演員。

我不能提供代碼,因爲我說,我甚至不知道如何tp取消選中一個按鈕,谷歌沒有幫助。這甚至有可能嗎?如果沒有,我會很樂意提供其他建議。

回答

3

看看ButtonGroup的

ButtonGroup的是不是一個演員,也沒有視覺效果。按鈕被添加到它,它強制執行最小和最大數量的選中按鈕。這允許按鈕(按鈕,文本按鈕,複選框等)被用作「收音機」按鈕。 https://github.com/libgdx/libgdx/wiki/Scene2d.ui#wiki-ButtonGroup

也可以嘗試,並看看有用的javadoc,瞭解它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: 
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.