[LibGDX] move between screens

hello , i’m still using libGdx 0.99
in my older project i used to move between screen when a button is clicked (lets say in main menu)
using this :


if(buttonName.isPressed()){
				((Game) Gdx.app.getApplicationListener()).setScreen(new ScreenName());

for some reason this is not working on my new project … i get this error:
“The method getApplicationListener() is undefined for the type Application”
any idea how to over come this ?

Hover over game and import it.

can not do that , i have even updated project with nightly files , still no effect
tried to clean project but that resulted of deleting my main class !!

after updating to nightly , this is the error i get :
Game cannot be resolved to a type

Game no longer extends ApplicationListener, it extends ApplicationAdapter.

This might be the problem, I’ll have a look when I’m gone.

after various nightly files updates and project clean and refresh , it finally works as:


((Game) Gdx.app.getApplicationListener()).setScreen(new Play());

i think starting V1 game extends ApplicationAdapter

I’m pretty new, but based on what I saw in the Simple Game Tutorial from LibGDX and the Breakout game I’m working on, it’s fairly simple.

Essentially, your main class for the project will manage everything you need and you can pass an instance of it to your screens so that they can use everything from that one class and still remain lightweight and functional.

I’ve omitted all of the code that doesn’t pertain so you can see what I’ve done.
In my case, the main class is BreakOutGame:



public class BreakOutGame extends Game {
	
	@Override
	public void create() {		
		
		this.setScreen(new MainMenuScreen(this)); // This is the code that actually sets the first screen of your game.
		
	}

	@Override
	public void render() {
		super.render(); // Don't forget to use super.render();
	}
}

Notice in the onCreate(); method is the code for switching the screens. That’s where you would create a class to serve as one of your screens, such as MainMenuScreen in my case.

Create a class and implement Screen, then generate the methods it needs.

Use a constructor to serve as your onCreate() method with a parameter of the instance of the game. In my case:



public class MainMenuScreen implements Screen {

public MainMenuScreen(BreakOutGame bog)
	{
		this.bog = bog;

	}

Hope it helps!