Skip to content

Update to Scene Changing

Millie Macdonald edited this page Jan 18, 2017 · 1 revision

Update to Scene Changing

to change your button handlers to use GameManager.changeScenereplace;

exampleButton.setOnAction(this::handleButton);
...
private void handleButton(ActionEvent event) {
		Stage primaryStage = (Stage) exmapleButton.getScene().getWindow();
		Parent exampleScreen = null;
		try {
			// getResource() should look in src/main/resources
			exampleScreen = FXMLLoader.load(getClass().getResource("/fxml/NewScreen.fxml"));
		} catch (IOException e) {
			logger.debug("IO Exception when loading NewScreen.fxml");
			System.exit(1);
		}
		Scene scene = new Scene(exampleScreen);
		primaryStage.setScene(scene);
	}

with

exampleButton.setOnAction(e -> GameManager.changeScene(exampleButton, "MenuScreen.fxml"));

Extra

GameManager.changeScene is static so you do not need to get an instance of GameManager.

Parameters

changeScene takes a JavaFX Control object and a String of the resource name.

The resource name needs to be the name of fxml file in 'resources/fxml/' including .fxml file extension, DO NOT include the full path to the file.

Home

Saving and Loading

Statistics tracking

Game Play

APIs


Game Guide

Other Guides

Design Guides

Overviews

Features

Animations

Splash Screen & Create Account Screen

Player Account Settings

AI

Duck Dust


Brainstorming


Future Development


http://cultofthepartyparrot.com/parrots/partyparrot.gifhttp://cultofthepartyparrot.com/parrots/partyparrot.gifhttp://cultofthepartyparrot.com/parrots/partyparrot.gifhttp://cultofthepartyparrot.com/parrots/partyparrot.gif

Clone this wiki locally