Java AnimationTimer stop()方法不停止
我知道,可以使用Java AnimationTimer stop()方法不停止,java,animation,Java,Animation,我知道,可以使用this.stop函数从其重写的handle()方法中停止正在进行的动画。下面的代码来自一个游戏,它应该在游戏获胜并显示警报后停止运行动画。相反,警报会弹出无数次 new AnimationTimer() { @Override public void handle(long now) { if (game.isInProgress()) { nextFrame(); } else { if (game.isWon()) {
this.stop
函数从其重写的handle()
方法中停止正在进行的动画。下面的代码来自一个游戏,它应该在游戏获胜并显示警报后停止运行动画。相反,警报会弹出无数次
new AnimationTimer() {
@Override
public void handle(long now) {
if (game.isInProgress()) {
nextFrame();
} else {
if (game.isWon()) {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Game Over!");
alert.setHeaderText("Congratulations, you have won the game!");
alert.setContentText(toolbarModule + ": " + game.getLevel().getScoreObject().getScore()
+ ", Time Remaining: " + toolbarModule.getTimeString() + "\n Rank: "
+ toolbarModule.getRankString());
alert.show();
} else {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Game Over!");
alert.setHeaderText("Sadly, you have lost the game!");
alert.setContentText("Time passed: " + game.getLevel().getTimeLimit());
alert.show();
}
new EndScene(game, stage);
this.stop();
}
}
}.start();
我做错了什么
任何帮助都将不胜感激,。实际上是合乎逻辑的(通常是)。
alert.show
功能等待用户确认弹出窗口。同时,handle()
方法多次运行该方法。我需要的是运行这个弹出窗口一次。我通过将警报包含在一个条件中来实现这一点。像这样:
if (!victoryMessageReceived) {
victoryMessageReceived = true;
if (game.isWon()) {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Game Over!");
alert.setHeaderText("Congratulations, you have won the game!");
alert.setContentText(toolbarModule + ": "
+ game.getLevel().getScoreObject().getScore() + ", Time Remaining: "
+ toolbarModule.getTimeString() + "\n Rank: " + toolbarModule.getRankString());
alert.show();
} else {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Game Over!");
alert.setHeaderText("Sadly, you have lost the game!");
alert.setContentText("Time passed: " + game.getLevel().getTimeLimit());
alert.show();
}
}
谢谢大家的努力 我猜出来了。实际上是合乎逻辑的(通常是)。
alert.show
功能等待用户确认弹出窗口。同时,handle()
方法多次运行该方法。我需要的是运行这个弹出窗口一次。我通过将警报包含在一个条件中来实现这一点。像这样:
if (!victoryMessageReceived) {
victoryMessageReceived = true;
if (game.isWon()) {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Game Over!");
alert.setHeaderText("Congratulations, you have won the game!");
alert.setContentText(toolbarModule + ": "
+ game.getLevel().getScoreObject().getScore() + ", Time Remaining: "
+ toolbarModule.getTimeString() + "\n Rank: " + toolbarModule.getRankString());
alert.show();
} else {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Game Over!");
alert.setHeaderText("Sadly, you have lost the game!");
alert.setContentText("Time passed: " + game.getLevel().getTimeLimit());
alert.show();
}
}
谢谢大家的努力