This is kinda the source code. After a lot of tries I managed to get to this point, but I'm still getting a lot of errors.
java.lang.reflect.InvocationTargetException Caused by: java.lang.RuntimeException: Exception in Application start method Caused by: java.lang.IllegalArgumentException: Children: duplicate children added: parent = Grid hgap=0.0, vgap=0.0, alignment=TOP_LEFT
I'm not even sure if what I'm trying to achieve here is going to the right direction or if it is completely wrong.
The source code runs the game without any additional screens. I want to add a simple start screen before the game starts. A play button and a dropdown menu. The button sends you to the game and in the dropdown menu you choose a color and it saves it for in-game use.
@Override
public void start(Stage primaryStage) {
//MENU ITEMS HERE//
gameSceneGrid = new GridPane();
GridPane root = new GridPane();
root.add(MENU, 0, 0);
root.add(gameSceneGrid, 0, 1);
root.getChildren().addAll(gameSceneGrid);
gameScene = new Scene(root,600,600);
Button playButton = new Button("Play Game");
playButton.setOnAction(e -> primaryStage.setScene(gameScene));
startSceneGrid = new GridPane();
startSceneGrid.add(playButton,0,1);
GridPane root0= new GridPane();
root0.add(MENU,0,0);
root0.add(startSceneGrid,0,1);
root0.getChildren().addAll(startSceneGrid);
startScene = new Scene(root0,200,200);
primaryStage.setScene(startScene);
primaryStage.setTitle(StartMeUp.GAME_NAME);
primaryStage.show();
loadDefaultSaveFile(primaryStage);
}
void loadDefaultSaveFile(Stage primaryStage)
{
this.primaryStage = primaryStage;
System.out.println("Hi");
InputStream in = getClass().getClassLoader().getResourceAsStream("sample/SampleGame.skb");
System.out.println(in);
initializeGame(in);
System.out.println("Hi");
setEventFilter();
System.out.println("Hi");
}
This is the original source code for the game screen/scene
gameGrid = new GridPane();
GridPane root = new GridPane();
root.add(MENU, 0, 0);
root.add(gameGrid, 0, 1);
primaryStage.setTitle(StartMeUp.GAME_NAME);
primaryStage.setScene(new Scene(root));
primaryStage.show();
loadDefaultSaveFile(primaryStage);