mineshmshah
mineshmshah

Reputation: 480

JavaFX wait for animation method to finish before going to next method

How do I get JavaFX to wait for one method with an animation to finish before moving to the next method? So my code is as follows:

public void spinWheel(){
        RotateTransition rotation = new 
        rotation.setByAngle(-(720+(15*(i+(24-finalIndex)))));
        rotation.play();
        wheelResult=wheel.spinWheel(i);

spinButton.setOnAction(e->{
    spinButton.setDisable(true);
    wheelGui.spinWheel();
    spinGame();
    });

So the spinwheel() methods is the animation. It is essentially a wheel spinning. The method after prints some code and in some cases reactivates the button. However this is instantaneous. I want the animation to finish before the next method runs as the text comes to fast or the button turns on again and can interrupt the action.

Upvotes: 5

Views: 7578

Answers (1)

jns
jns

Reputation: 6952

You can use

RotateTransition rotateTransition = new RotateTransition();
rotateTransition.setOnFinished(e -> yourMethod())
rotateTransition.play();

Upvotes: 4

Related Questions