How can I switch between different screens that implement Screen
?
1 Answer
Something like below. Off course you need to add the Button to the stage, create a skin and the OptionScreen yourself.
@Override
public void show() {
final OptionScreen optionScreen = new OptionScreen();
TextButton optionButton = new TextButton("Options", skin);
optionButton.addListener(new ClickListener(){
@Override
public void clicked(InputEvent event, float x, float y) {
((Game) Gdx.app.getApplicationListener()).setScreen(optionScreen);
}
});
}
Because we use optionScreen
inside a listener here it has to be final since the application never knows when the button is clicked it. You can also just create a new
instance of OptionScreen
inline setScreen(new OptionScreen);
.
Point (mouse position) inside Rectangle (button bounds)
. It is like asking what will happen if I press "q" in a game. In one game you might use a spell, in another you might quit the game. \$\endgroup\$