[英]Perform action for certain amount of time JavaFX
我正在做一个游戏,我想播放一个介绍性图片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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.