1
我知道可以使用this.stop
函數從正在重寫的handle()
方法中停止正在進行的動畫。下面的代碼來自遊戲,在遊戲結束並顯示警報後,它應該停止運行動畫。相反,警報彈出無數次。AnimationTimer stop()方法不會停止
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();
我在做什麼錯?
任何幫助,將大大讚賞,