diff --git a/src/de/bricked/ui/LevelController.java b/src/de/bricked/ui/LevelController.java index a5cf4961b7b2709f60d4eb712e42d03a4355c8cc..c112bb592080e125ec68d4896589d4be2c7ce5dc 100644 --- a/src/de/bricked/ui/LevelController.java +++ b/src/de/bricked/ui/LevelController.java @@ -561,7 +561,13 @@ public class LevelController labelPause.setTranslateX(((gamePaneWidth - t.getLayoutBounds().getWidth() + 10) / 2) + 22); labelPause.setTranslateY(((gamePaneHeight - t.getLayoutBounds().getHeight()) / 2) + 125); - anchorPane.getChildren().add(labelPause); + anchorPane.getChildren().add(labelPause); + + //pause all timedPowerUps + for(CountdownTimer currentTimer : timedPowerUps) + { + currentTimer.stop(); + } } private void restart() @@ -571,6 +577,13 @@ public class LevelController fps = 0; anchorPaneGame.setOpacity(1.0); anchorPane.getChildren().remove(anchorPane.getChildren().size() - 1); + + //restart all timedPowerUps + for(CountdownTimer currentTimer : timedPowerUps) + { + currentTimer.start(); + } + timer.start(); } diff --git a/src/de/bricked/utils/CountdownTimer.java b/src/de/bricked/utils/CountdownTimer.java index 84cb3ace09343674e10c5a97874acbadbc11371b..6f148ce5e26e2c363b7903f2d7587b7ef149e167 100644 --- a/src/de/bricked/utils/CountdownTimer.java +++ b/src/de/bricked/utils/CountdownTimer.java @@ -12,17 +12,33 @@ public class CountdownTimer { private int count; private HBox hbox; + private LevelController levelController; private Timer timer; + private TimerTask task; + private CountdownTimer self; public CountdownTimer(int seconds, HBox hbox, LevelController levelController) { this.count = seconds; - this.hbox = hbox; + this.hbox = hbox; + self = this; - CountdownTimer self = this; - - timer = new Timer(); - TimerTask task = new TimerTask() + start(); + } + + public void addSecondsToTimer(int seconds) + { + this.count += seconds; + } + + public HBox getHBox() + { + return hbox; + } + + public void start() + { + task = new TimerTask() { @Override public void run() @@ -52,22 +68,13 @@ public class CountdownTimer } } }; + timer = new Timer(); timer.schedule(task, 0, 1000); } - public void addSecondsToTimer(int seconds) - { - this.count += seconds; - } - - public HBox getHBox() - { - return hbox; - } - public void stop() { - timer.cancel(); + timer.cancel(); timer.purge(); } } \ No newline at end of file