This is how I always implement screen shielding:
First, the main class should extend Game (From com.badlogic.gdx.Game ), and you will need to have a new field of type Game :
public class ConnectFourApplication extends Game{ private Game game;
Now initialize the Game in the constructor:
public ConnectFourApplication(){ game = this; // Since this class extends Game
To set the screen on MainScreen , now all you have to do is use the setScreen(new MainScreen(game)); method setScreen(new MainScreen(game)); (passing Game so that we can set screens from the MainScreen class) Now you need a new constructor for the MainScreen class and a new field:
private Game game; public MainScreen(Game game){ this.game = game;
Now you can use game.setScreen(new Screen(game)); to set the screen to another class that implements Screen .
But now, in the main class, in the render() method, you should use super.render(); to use anything you want from other screen renderings!
public void render() { clearWhite(); super.render(); }
PS: Make sure that the class you make as a screen is, in fact, implements Screen .
source share