Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java AnimationTimer stop()方法不停止_Java_Animation - Fatal编程技术网

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();
        }        
      }
谢谢大家的努力