Problem is the following: Once I go to my game from the main menu, everything renders correctly, but the buttons from the main menu still work if I tap where they should be. (For instance, if I click on the play button again, the game will restart)
Help?
Render method:
public void render () {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
if(currentState == GameState.ACTOR) {
stage.act();
stage.draw();
Table.drawDebug(stage);
} else if(currentState == GameState.GAME) {
if(playActor == null) {
currentState = GameState.ACTOR;
return;
} else {
batch.begin();
playActor.render(batch);
batch.end();
}
}
}
MainMenu.java
package com.fmeg.tapout.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.fmeg.tapout.TapoutGame;
public class MainMenu extends Table {
private TapoutGame game;
// Setup the TextButtons for the Menu
TextButton btnPlay30s, btnPlay1m, btnPlay5m, btnAchievements, btnHighscores;
Label gameName;
public MainMenu(TapoutGame _game) {
super(_game.getSkin());
this.game = _game;
setupWidgets();
setupLayout();
setupEvents();
}
private void setupWidgets() {
BitmapFont title_font = new BitmapFont();
title_font.scale(4f);
title_font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
LabelStyle title_font_style = new LabelStyle(title_font, Color.WHITE);
gameName = new Label("Game Name", title_font_style);
btnPlay30s = new TextButton("30 Second Challenge!", game.getSkin());
btnPlay1m = new TextButton("1 Minute Challenge!", game.getSkin());
btnPlay5m = new TextButton("5 Minute Challenge!", game.getSkin());
btnAchievements = new TextButton("Achievements!", game.getSkin());
btnHighscores = new TextButton("Highscores!", game.getSkin());
}
//table.add(btn).size(100, 100);
private void setupLayout() {
setFillParent(true);
add(gameName).row();
pad(10).defaults().space(20).fillX();
add(btnPlay30s).size((Gdx.graphics.getWidth()) - (Gdx.graphics.getWidth() / 4), Gdx.graphics.getHeight() / 16).row();
add(btnPlay1m).size((Gdx.graphics.getWidth()) - (Gdx.graphics.getWidth() / 4), Gdx.graphics.getHeight() / 16).row();
add(btnPlay5m).size((Gdx.graphics.getWidth()) - (Gdx.graphics.getWidth() / 4), Gdx.graphics.getHeight() / 16).row();
add(btnAchievements).size((Gdx.graphics.getWidth()) - (Gdx.graphics.getWidth() / 4), Gdx.graphics.getHeight() / 16).row();
add(btnHighscores).size((Gdx.graphics.getWidth()) - (Gdx.graphics.getWidth() / 4), Gdx.graphics.getHeight() / 16).row();
}
private void setupEvents() {
btnPlay30s.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
game.setGame(new Play(game, 30));
game.setState(TapoutGame.GameState.GAME);
}
});
btnAchievements.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
game.setScreen(new Achievements(game));
}
});
}
}
I guess what the problem is, is that the MainMenu is never being destroyed, how can I do that?