我一直试图在场景之间放置一个加载场景,我的想法是:
显然,整个加载场景都将被忽略,而所需的场景则只是直接设置。我敢打赌,线程不能同时工作。
这是任务部分和相关属性。
private Stage pokeWindow = new Stage();
private Scene currentScene;
private boolean sceneReady = false;
private String targetScene;
private int genericInt;
private final Task setGenericScene = new Task(){
@Override
protected Object call() throws Exception {
sceneReady = false;
if(targetScene.equals("summaryScene")){
setSummaryScene(genericInt);
sceneReady = true;
}
return null;
}
};
这是加载场景。
public void setLoadingScene(){
Thread loadScreen = new Thread(setGenericScene);
loadScreen.start();
if(!sceneReady){
GridPane background = new GridPane();
BackgroundImage loadingBG = new BackgroundImage(new Image((new File("src/resources/tiles/pokedexfullbg.png")).toURI().toString()), BackgroundRepeat.REPEAT, BackgroundRepeat.REPEAT, BackgroundPosition.DEFAULT, BackgroundSize.DEFAULT);
background.setBackground(new Background(loadingBG));
[...]
[more javafx code regarding the loading scene]
Scene loadingScene = new Scene(background, 512, 416);
this.pokeWindow.setScene(loadingScene);
animation1.play();
animation2.play();
animation3.play();
animation4.play();
animation5.play();
animation6.play();
animation7.play();
animation8.play();
while(!sceneReady){}
}
this.pokeWindow.setScene(currentScene);
}