按下后退按钮并恢复后,我的游戏中出现黑屏

时间:2016-06-13 12:52:54

标签: android libgdx dispose

我正在使用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之外,似乎所有东西都被处理掉了(?),但我不明白这有什么问题。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:-1)

您的代码几乎已经完成,这需要放入您的AndroidLauncher(重新加载资源onResume):

@Override
protected void onResume() {
    Assets.unload();
    Assets.load();
    ASSET_MANAGER.finishLoading();
    super.onResume();
}