Hm I think I have found the problem but not in code.
This only happens if the app is sent to the background on the main menu, this does not happen on the game screen it simply pauses.
If I terminate the game using the task manager and open it back up, it loads fine. So it seems that upon bringing the app back to the front, it is as if it gets the images stored in memory mixed up, if that is possible.
Here is my MainMenu class:
public class MainMenuScreen implements Screen {
public UIManager uiManager;
public MainMenuScreen() {
uiManager = new UIManager();
uiManager.initMain();
Gdx.input.setInputProcessor(uiManager);
Gdx.input.setCursorCatched(false);
Gdx.input.setCatchBackKey(true);
Gdx.input.setCatchMenuKey(true);
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
uiManager.act(delta);
uiManager.draw();
// Table.drawDebug(uiManager);
}
Here is my UIManager thing, basically just the Scene2D stage:
public class UIManager extends Stage {
/** Camera */
public OrthographicCamera cam;
/** Skin */
public Skin skin;
/** Main table */
public Table table;
public UIManager() {
cam = new OrthographicCamera(640, 480);
cam.setToOrtho(false);
setCamera(cam);
skin = new Skin();
table = new Table(skin);
table.debug();
if (Gdx.app.getType() == ApplicationType.Desktop) {
AssetLoader.BUTTON_UP.setSize(256, 128);
AssetLoader.BUTTON_DOWN.setSize(256, 128);
}
skin.add("buttondown", AssetLoader.BUTTON_DOWN);
skin.add("buttonup", AssetLoader.BUTTON_UP);
}
public void initMain() {
TextButtonStyle style = new TextButtonStyle();
style.font = Gdx.app.getType() == ApplicationType.Desktop ? AssetLoader
.fontGenerator("data/font/pricedown.ttf", 40) : AssetLoader
.fontGenerator("data/font/pricedown.ttf", 64);
style.down = skin.getDrawable("buttondown");
style.up = skin.getDrawable("buttonup");
style.unpressedOffsetX = -2;
style.unpressedOffsetY = 2;
LabelStyle labelStyle = new LabelStyle();
if (Gdx.app.getType() == ApplicationType.Desktop) {
labelStyle.font = AssetLoader.fontGenerator(
"data/font/pricedown.ttf", 48);
} else {
labelStyle.font = AssetLoader.fontGenerator(
"data/font/pricedown.ttf", 156);
}
Label heading = new Label("Falling Rocks", labelStyle);
TextButton play = new TextButton("PLAY", style);
TextButton highscores = new TextButton("HIGHSCORES", style);
TextButton exit = new TextButton("EXIT", style);
play.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
((Game) Gdx.app.getApplicationListener())
.setScreen(new GameScreen());
}
});
highscores.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
}
});
exit.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
Gdx.app.exit();
}
});
table.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
table.setFillParent(true);
table.add(heading).row();
table.add(play).row();
table.add(highscores).row();
table.add(exit);
addActor(table);
}
}
I ran some tests, basically printing out the button textures and fonts to the console and the memory ID does not change.