2016-04-08 48 views
0

我最近在我的libGDX程序中發現了一個奇怪的問題。當我啓動我的程序時,首先顯示SplashScreen,然後顯示MainMenu屏幕,然後可以輸入程序。問題是,如果我在主菜單上更改screen,則我的所有TextButton都變成完全黑色,並且其文本字符變成黑色框。 Before changing screenlibGDX - 更換屏幕後的黑色按鈕和文字

After changing screen

這會影響所有其他屏幕的所有文本框(我用閃按鈕重新加載的MainMenu)。我的想法是,我的JSON在某種程度上是錯誤的。因爲當我停止使用我的JSON中的drawable時,而是使用FreeTypeFont而不是我的BitmapFont,至少字體不再變黑。我已經使用驗證,他們說有我的JSON沒有問題,但在這裏它是反正(TextButtonStyle在底部):

{ 
"com.badlogic.gdx.graphics.Color": { 
    "white": { 
     "r": 1, 
     "g": 1, 
     "b": 1, 
     "a": 1 
    }, 

    "black": { 
     "r": 0, 
     "g": 0, 
     "b": 0, 
     "a": 1 
    }, 

    "red": { 
     "r": 1, 
     "g": 0, 
     "b": 0, 
     "a": 1 
    }, 

    "green": { 
     "r": 0, 
     "g": 1, 
     "b": 0, 
     "a": 1 
    }, 

    "blue": { 
     "r": 0, 
     "g": 0, 
     "b": 1, 
     "a": 1 
    }, 

    "dark_grey": { 
     "r": 0.8, 
     "g": 0.8, 
     "b": 0.8, 
     "a": 1 
    } 
}, 

"com.badlogic.gdx.graphics.g2d.BitmapFont": { 
    "white": { 
     "file": "data/fonts/white.fnt" 
    }, 

    "black": { 
     "file": "data/fonts/black.fnt" 
    } 
}, 

"com.badlogic.gdx.scenes.scene2d.ui.Window$WindowStyle": { 
    "default": { 
     "titleFont": "black", 
     "titleFontColor": "dark_grey" 
    } 
}, 

"com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle": { 
    "default": { 
     "font": "white", 
     "fontColor": "white" 
    } 
}, 

"com.badlogic.gdx.scenes.scene2d.ui.List$ListStyle": { 
    "default": { 
     "font": "white", 
     "fontColorUnselected": "white", 
     "fontColorSelected": "black", 
     "selection": "default.selection" 
    } 
}, 

"com.badlogic.gdx.scenes.scene2d.ui.ScrollPane$ScrollPaneStyle": { 
    "default": { 
     "hScrollKnob": "button.up", 
     "vScrollKnob": "button.up" 
    } 
}, 

"com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle": { 
    "default": { 
     "up": "button.up", 
     "down": "button.down", 
     "font": "black", 
     "pressedOffsetX": 1, 
     "pressedOffsetY": -1 
    } 
} 
} 

此處,我添加和更改按鈕風格的代碼。

// Splash Screen button 
    buttonSplash = new TextButton("SPLASH SCREEN", skin); 
    buttonSplash.addListener(new ClickListener() { 
     @Override 
     public void clicked(InputEvent event, float x, float y) { 
      // When you click the button, create a new screen 
      ((Game) Gdx.app.getApplicationListener()).setScreen(new SplashScreen()); 
     } 
    }); 
    buttonSplash.pad(20); 
    //Rest of the buttons.... 

如果你覺得你需要的全部代碼,我可以張貼爲好,但它是相當長的這就是爲什麼我從張貼忍住了。

即時編輯:嘗試全新的JSON(與libGDX自帶的),我仍然有同樣的問題。

+0

您是否在使用靜態的'AssetManager'? – Madmenyo

回答

0

看起來問題來自處置skin。我在外部類中使用了一個static Skin對象作爲我的皮膚,供所有需要該皮膚的類使用。我的問題是我把皮膚放在其中一個屏幕上,處理所有其他課程使用的皮膚。我解決了這個問題,只需在保存我所有皮膚的類中創建一個dispose();方法,然後在退出遊戲時處置它們。

+0

你要麼在錯誤的時間處置,要麼重新加載並重新初始化皮膚 –

+0

當你沒有完全解決它時,你不應該回答自己的問題。改變你的初始問題,包括你的更新或添加評論(你可以評論我認爲的10個聲望)。 – Madmenyo

+0

我實際上完全解決了大約一個小時後,但忘記編輯我的答案,但謝謝你的洞察力。 – Charanor