Example usage for javafx.animation FadeTransition FadeTransition

List of usage examples for javafx.animation FadeTransition FadeTransition

Introduction

In this page you can find the example usage for javafx.animation FadeTransition FadeTransition.

Prototype

public FadeTransition() 

Source Link

Document

The constructor of FadeTransition

Usage

From source file:com.github.vatbub.tictactoe.view.Main.java

private void showLooser(Board.WinnerInfo winnerInfo) {
    String looserName = board.getOpponent(winnerInfo.winningPlayer).getName();
    guiAnimationQueue.submitWaitForUnlock(() -> {
        ShakeTransition anim = new ShakeTransition(gamePane, null);
        anim.playFromStart();/*from w w w .java 2 s  . c  om*/

        Timeline timeline = new Timeline();

        Circle c1 = new Circle((452 / 600.0) * looserPane.getWidth(), (323 / 640.0) * looserPane.getHeight(),
                0);
        GaussianBlur circleBlur = new GaussianBlur(30);
        c1.setEffect(circleBlur);
        looseImage.setClip(c1);
        addWinLineOnLoose(winnerInfo);

        KeyValue keyValue1 = new KeyValue(c1.radiusProperty(), 0);
        KeyFrame keyFrame1 = new KeyFrame(Duration.millis(800), keyValue1);
        KeyValue keyValue2 = new KeyValue(c1.radiusProperty(), (500 / 640.0) * looserPane.getHeight());
        KeyFrame keyFrame2 = new KeyFrame(Duration.millis(900), keyValue2);

        timeline.getKeyFrames().addAll(keyFrame1, keyFrame2);

        looseMessage.setOpacity(0);
        looserText.setText(looserName + " lost :(");
        looserPane.setVisible(true);
        looserPane.setOpacity(1);

        timeline.setOnFinished((event) -> {
            looseImage.setClip(null);
            winLineGroup.setClip(null);
            blurGamePane();
            PauseTransition wait = new PauseTransition();
            wait.setDuration(Duration.seconds(1));
            wait.setOnFinished((event2) -> {
                FadeTransition looseMessageTransition = new FadeTransition();
                looseMessageTransition.setNode(looseMessage);
                looseMessageTransition.setFromValue(0);
                looseMessageTransition.setToValue(1);
                looseMessageTransition.setDuration(Duration.millis(500));
                looseMessageTransition.setAutoReverse(false);
                looseMessageTransition.play();
            });

            wait.play();
        });

        timeline.play();
    });

}

From source file:com.github.vatbub.tictactoe.view.Main.java

private void fadeNode(Node node, double toValue, boolean block, Runnable onFinish) {
    guiAnimationQueue.submit(() -> {/* ww  w.  j  ava 2  s  .c o m*/
        if (block) {
            guiAnimationQueue.setBlocked(true);
        }
        if (!node.isVisible()) {
            node.setOpacity(0);
            node.setVisible(true);
        }

        FadeTransition fadeTransition = new FadeTransition();
        fadeTransition.setNode(node);
        fadeTransition.setFromValue(node.getOpacity());
        fadeTransition.setToValue(toValue);
        fadeTransition.setDuration(Duration.seconds(animationSpeed));
        fadeTransition.setAutoReverse(false);

        fadeTransition.setOnFinished((event) -> {
            if (toValue == 0) {
                node.setEffect(null);
                node.setVisible(false);
            }
            if (block) {
                guiAnimationQueue.setBlocked(false);
            }
            if (onFinish != null) {
                onFinish.run();
            }
        });

        fadeTransition.play();
    });
}