我正在制作一个游戏,我想播放一个介绍图片 3 秒钟,然后调用方法来开始游戏。我尝试过使用 Thread.sleep 但我知道这可能不是一个好方法,而且它不起作用。有人知道有什么好方法吗?
这是我的代码:
ImageView intro = new ImageView(new Image("/Resources/Intro.png"));
root.getChildren().add(intro);
if (startGame) {
InitializeGame.InitGame();
InitializeGame.StartGame();
}
}
谢谢!
最佳答案
使用PauseTransition
。从您的代码中不清楚您想要在暂停后执行哪些部分,但类似于:
ImageView intro = new ImageView(new Image("/Resources/Intro.png"));
root.getChildren().add(intro);
PauseTransition pause = new PauseTransition(Duration.seconds(3));
pause.setOnFinished(e -> {
InitializeGame.InitGame();
InitializeGame.StartGame();
});
pause.play();
关于java - 在一定时间内执行操作 JavaFX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41798369/