2014-01-31 34 views
2

在我的libGdx項目中,我使用.json文件來設置屬性對話框的按鈕樣式。我有兩個按鈕:紅色(OFF)和綠色(ON)。如何使用JSON更改LibGDX中屬性對話框的樣式?

我想在它們之間切換。有沒有在JSON文件中設置樣式的方法?

com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: { 
    default: { down: ON_Button, up: ON_Button, font: default-font, fontColor: white }, 
    toggle: { down: ON_Button, up: ON_Button, checked: OFF_Button, font: default-font, fontColor: white, downFontColor: red } 
}, 

回答

2

按鈕支持setChecked方法,所以你可以這樣做一種風格:

com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: { 
    toggle: { 
     down: OFF_Button, // <- pressed 
     up: OFF_Button, // <- not checked 
     checked: ON_BUTTON, // <- checked 
     font: default-font, 
     fontColor: white 
    }, 
}, 

,並致電按鈕切換狀態的setChecked(bool)方法。此外,按鈕會自動切換選中狀態。

+0

不應該這是切換而不是默認?我並不十分了解JSON和這種風格,但儘管我瞭解他正在尋找的風格應該稱爲切換(這不是技術方面的命名)。他的JSON文件是正確的嗎? – Springrbua

+0

@Springrbua,是的,這種風格應該命名爲「複選框」或「切換」或類似的東西。另外,'TextButtonStyle'只需要'font'字段,所以,是的,看起來是正確的。 – desertkun

+0

謝謝。直到現在,我並不需要這個在我的遊戲中,因爲我沒有菜單,但是當我執行菜單時,這個信息將有助於希望:P謝謝。 +1 – Springrbua