Make a JavaFX application wait between an animation

后端 未结 1 1444
再見小時候
再見小時候 2021-01-26 01:01

I am working on a simple game using JavaFX. What I want here is that at the end of the loop, the application waits for a specified period of time, and then runs again.

W

相关标签:
1条回答
  • 2021-01-26 01:31

    Put all the animations into a SequentialTransition, separated by PauseTransitions:

    private void playWonAnimation(){
        Random rand = new Random();
        SequentialTransition seq = new SequentialTransition();
        for (Node block: tower02List) {
            double xTrans = rand.nextInt(800) + 700;
            double yTrans = rand.nextInt(800) + 700;
    
            int translateTime = 2500 ;
            int oneRotationTime = 1200 ;
    
            TranslateTransition translate = new TranslateTransition(Duration.millis(translateTime), block);
            xTrans = (xTrans > 1100) ? xTrans : -xTrans;
            translate.setByX(xTrans);
            translate.setByY(-yTrans);
    
            RotateTransition rotate = new RotateTransition(Duration.millis(translateTime), block);
            rotate.setByAngle(360 * translateTime / oneRotationTime);
    
            seq.getChildren().add(new ParallelTransition(translate, rotate));
            seq.getChildren().add(new PauseTransition(Duration.seconds(1.0)));
        }
    
        seq.play();
    }
    
    0 讨论(0)
提交回复
热议问题