我正在使用LibGDX創建遊戲。我已經實現AssetManager
來加載所有資產,並且我還創建了一個類GameSkin
,它將許多按鈕樣式以及類似的東西添加到皮膚,因此我不必手動執行。那就是:我按下後退按鈕後會在我的遊戲中看到黑屏,並且繼續
public class GameSkin extends Skin {
private static final AssetManager ASSET_MANAGER = Assets.getAssetManager();
private TextureAtlas atlas;
private FreeTypeFontGenerator generator;
private FreeTypeFontGenerator.FreeTypeFontParameter parameter;
private BitmapFont defaultFont;
private TextButton.TextButtonStyle redButtonStyle, orangeButtonStyle, greenButtonStyle, blueButtonStyle, defaultButtonStyle;
private Label.LabelStyle labelStyle;
private Window.WindowStyle windowStyle, firstTimeWindowStyle;
public GameSkin() {
Assets.load();
ASSET_MANAGER.finishLoading();
atlas = ASSET_MANAGER.get("uiskin.atlas");
addRegions(atlas);
generator = new FreeTypeFontGenerator(Gdx.files.internal("font/komika.ttf"));
parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
parameter.size = 100;
defaultFont = generator.generateFont(parameter);
generator.dispose();
defaultButtonStyle = new TextButton.TextButtonStyle();
redButtonStyle = new TextButton.TextButtonStyle();
orangeButtonStyle = new TextButton.TextButtonStyle();
greenButtonStyle = new TextButton.TextButtonStyle();
blueButtonStyle = new TextButton.TextButtonStyle();
redButtonStyle.font = defaultFont;
redButtonStyle.up = getDrawable("rbup");
redButtonStyle.down = getDrawable("rbdown");
orangeButtonStyle.font = defaultFont;
orangeButtonStyle.up = getDrawable("obup");
orangeButtonStyle.down = getDrawable("obdown");
greenButtonStyle.font = defaultFont;
greenButtonStyle.up = getDrawable("gbup");
greenButtonStyle.down = getDrawable("gbdown");
blueButtonStyle.font = defaultFont;
blueButtonStyle.up = getDrawable("bbup");
blueButtonStyle.down = getDrawable("bbdown");
defaultButtonStyle.font = defaultFont;
defaultButtonStyle.up = getDrawable("obup");
defaultButtonStyle.down = getDrawable("obdown");
labelStyle = new Label.LabelStyle(defaultFont, Color.WHITE);
windowStyle = new Window.WindowStyle(defaultFont, Color.WHITE, getDrawable("GT"));
firstTimeWindowStyle = new Window.WindowStyle(defaultFont, Color.WHITE, getDrawable("guide"));
add("default-font", defaultFont);
add("red-button", redButtonStyle);
add("orange-button", orangeButtonStyle);
add("green-button", greenButtonStyle);
add("blue-button", blueButtonStyle);
add("default", defaultButtonStyle);
add("default", labelStyle);
add("default", windowStyle);
add("first-time", firstTimeWindowStyle);
}
@Override
public void dispose() {
super.dispose();
}
}
似乎除了我在按鈕上使用的BitmapFont,所有東西都被丟棄(?),但我不明白什麼是錯誤的有了這個。任何人都可以幫忙
不要使用靜態引用您的資產或紋理。 https://github.com/libgdx/libgdx/wiki/Managing-your-assets#creating-an-assetmanager – Tenfour04
我用它,它的工作。謝謝! –