[英]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.