List of usage examples for javafx.animation Timeline Timeline
public Timeline()
From source file:com.github.vatbub.tictactoe.view.Main.java
private void showWinnerWithTwoHumanPlayers(Board.WinnerInfo winnerInfo) { guiAnimationQueue.submitWaitForUnlock(() -> addWinLineOnWin(winnerInfo, Color.YELLOW, () -> { twoHumansWinnerText.setText(winnerInfo.winningPlayer.getName() + " won :)"); double endX = twoHumansWinnerImage.getX(); double endY = twoHumansWinnerImage.getY(); AnchorPane.clearConstraints(twoHumansWinnerImage); twoHumansWinnerImage.setX(endX); twoHumansWinnerImage.setY(twoHumansWinnerImage.getY() + 300); // blurGamePane(); blurGamePane(10.0);// w w w . j av a 2s . c o m twoHumansWinMessage.setOpacity(0); twoHumansWinnerImage.setOpacity(0); twoHumansWinnerPane.setOpacity(1); twoHumansWinnerPane.setVisible(true); twoHumansWinnerImage.setVisible(true); Timeline timeline = new Timeline(); double S4 = 1.45; double x0 = 0.33; KeyValue twoHumansWinnerImageKeyValue1x = new KeyValue(twoHumansWinnerImage.xProperty(), endX, new CustomEaseOutInterpolator(S4, x0)); KeyValue twoHumansWinnerImageKeyValue1y = new KeyValue(twoHumansWinnerImage.yProperty(), endY, new CustomEaseOutInterpolator(S4, x0)); KeyValue twoHumansWinnerImageKeyValue1Opacity = new KeyValue(twoHumansWinnerImage.opacityProperty(), 1); KeyFrame twoHumansWinnerImageKeyFrame1 = new KeyFrame(Duration.millis(600), twoHumansWinnerImageKeyValue1x, twoHumansWinnerImageKeyValue1y, twoHumansWinnerImageKeyValue1Opacity); timeline.getKeyFrames().addAll(twoHumansWinnerImageKeyFrame1); timeline.setOnFinished((event) -> fadeNode(twoHumansWinMessage, 1, () -> { AnchorPane.setLeftAnchor(twoHumansWinnerImage, 0.0); AnchorPane.setBottomAnchor(twoHumansWinnerImage, 0.0); })); timeline.play(); })); }
From source file:com.github.vatbub.tictactoe.view.Main.java
private void addWinLineOnWin(Board.WinnerInfo winnerInfo, Paint color, Runnable onFinished) { Line originLine = new Line(0, 0, 0, 0); winLineGroup.getChildren().add(originLine); WinLine winLine = new WinLine(winnerInfo); double winLineEndX = winLine.endArc.getCenterX(); double winLineEndY = winLine.endArc.getCenterY(); winLine.startArc.setFill(color);//from w ww. j a v a 2 s .c o m winLine.startArc.setStrokeWidth(0); winLine.endArc.setFill(color); winLine.endArc.setStrokeWidth(0); winLine.rightLine.setStrokeWidth(0); winLine.leftLine.setStrokeWidth(0); winLine.centerLine.setStroke(color); winLine.centerLine.strokeWidthProperty().bind(winLine.startArc.radiusXProperty().multiply(2)); winLineGroup.getChildren().addAll(winLine.getAll()); blurNode(gamePane, 4); winLineGroup.setOpacity(0); GaussianBlur blur = new GaussianBlur(100); winLineGroup.setEffect(blur); winLineGroup.setBlendMode(BlendMode.DARKEN); winLineGroup.setVisible(true); double winLineAnimationX1 = 0.2; double winLineAnimationX2 = 0.5; KeyValue stretchKeyValue1x = new KeyValue(winLine.endArc.centerXProperty(), winLine.startArc.getCenterX()); KeyValue stretchKeyValue1y = new KeyValue(winLine.endArc.centerYProperty(), winLine.startArc.getCenterY()); KeyFrame stretchKeyFrame1 = new KeyFrame(Duration.millis(0), stretchKeyValue1x, stretchKeyValue1y); KeyValue stretchKeyValue2x = new KeyValue(winLine.endArc.centerXProperty(), winLine.startArc.getCenterX(), new CustomEaseBothInterpolator(winLineAnimationX1, winLineAnimationX2)); KeyValue stretchKeyValue2y = new KeyValue(winLine.endArc.centerYProperty(), winLine.startArc.getCenterY(), new CustomEaseBothInterpolator(winLineAnimationX1, winLineAnimationX2)); KeyFrame stretchKeyFrame2 = new KeyFrame(Duration.millis(100), stretchKeyValue2x, stretchKeyValue2y); KeyValue stretchKeyValue3x = new KeyValue(winLine.endArc.centerXProperty(), winLineEndX, new CustomEaseBothInterpolator(winLineAnimationX1, winLineAnimationX2)); KeyValue stretchKeyValue3y = new KeyValue(winLine.endArc.centerYProperty(), winLineEndY, new CustomEaseBothInterpolator(winLineAnimationX1, winLineAnimationX2)); KeyFrame stretchKeyFrame3 = new KeyFrame(Duration.millis(800), stretchKeyValue3x, stretchKeyValue3y); KeyValue opacityKeyValue1 = new KeyValue(winLineGroup.opacityProperty(), 0.8); KeyFrame opacityKeyFrame1 = new KeyFrame(Duration.millis(400), opacityKeyValue1); Timeline timeline = new Timeline(); timeline.getKeyFrames().addAll(stretchKeyFrame1, stretchKeyFrame2, stretchKeyFrame3, opacityKeyFrame1); timeline.play(); timeline.setOnFinished((event) -> onFinished.run()); }
From source file:com.github.vatbub.tictactoe.view.Main.java
private void showTie() { guiAnimationQueue.submitWaitForUnlock(() -> { double endX = tiePane.getWidth() - 230; double endY = 90; AnchorPane.clearConstraints(bowTie); bowTie.setX(endX);//from w w w . j a v a 2 s .co m bowTie.setY(-150); blurGamePane(); tieMessage.setOpacity(0); tiePane.setOpacity(1); tiePane.setVisible(true); bowTie.setVisible(true); Timeline timeline = new Timeline(); double S4 = 1.45; double x0 = 0.33; KeyValue keyValue1x = new KeyValue(bowTie.xProperty(), endX, new CustomEaseOutInterpolator(S4, x0)); KeyValue keyValue1y = new KeyValue(bowTie.yProperty(), endY, new CustomEaseOutInterpolator(S4, x0)); KeyFrame keyFrame1 = new KeyFrame(Duration.seconds(1), keyValue1x, keyValue1y); timeline.getKeyFrames().add(keyFrame1); timeline.setOnFinished((event) -> fadeNode(tieMessage, 1, () -> { AnchorPane.setRightAnchor(bowTie, tiePane.getWidth() - bowTie.getFitWidth() - endX); AnchorPane.setTopAnchor(bowTie, endY); })); timeline.play(); }); }
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 . ja v a 2 s.c o m*/ 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 addWinLineOnLoose(Board.WinnerInfo winnerInfo) { final double strokeWidth = 2; Line originLine = new Line(0, 0, 0, 0); winLineGroup.getChildren().add(originLine); WinLine winLine = new WinLine(winnerInfo); winLine.startArc.setFill(Color.TRANSPARENT); winLine.startArc.setStroke(Color.BLACK); winLine.startArc.setStrokeWidth(strokeWidth); winLine.endArc.setFill(Color.TRANSPARENT); winLine.endArc.setStroke(Color.BLACK); winLine.endArc.setStrokeWidth(strokeWidth); winLine.rightLine.setStrokeWidth(strokeWidth); winLine.leftLine.setStrokeWidth(strokeWidth); winLine.centerLine.setStrokeWidth(0); winLineGroup.getChildren().addAll(winLine.getAll()); winLineGroup.setOpacity(0);//from ww w .j a va 2 s .com GaussianBlur blur = new GaussianBlur(7); winLineGroup.setEffect(blur); winLineGroup.setVisible(true); KeyValue keyValue1 = new KeyValue(winLineGroup.opacityProperty(), 0); KeyFrame keyFrame1 = new KeyFrame(Duration.millis(900), keyValue1); KeyValue keyValue2 = new KeyValue(winLineGroup.opacityProperty(), 1); KeyFrame keyFrame2 = new KeyFrame(Duration.millis(950), keyValue2); Timeline timeline = new Timeline(); timeline.getKeyFrames().addAll(keyFrame1, keyFrame2); timeline.play(); }
From source file:com.github.vatbub.tictactoe.view.Main.java
private void blurNode(Node node, double toValue, @SuppressWarnings("SameParameterValue") Runnable onFinish) { guiAnimationQueue.submit(() -> {//from w w w. j a v a 2 s .c o m GaussianBlur blur = (GaussianBlur) node.getEffect(); if (blur == null) { blur = new GaussianBlur(0); node.setEffect(blur); } node.setEffect(blur); Timeline timeline = new Timeline(); KeyValue keyValue = new KeyValue(blur.radiusProperty(), toValue); KeyFrame keyFrame = new KeyFrame(Duration.seconds(animationSpeed), keyValue); timeline.getKeyFrames().add(keyFrame); timeline.setOnFinished((event) -> { if (toValue == 0) { node.setEffect(null); } if (onFinish != null) { onFinish.run(); } }); timeline.play(); }); }
From source file:com.github.vatbub.tictactoe.view.Main.java
private void updateMenuHeight(boolean includeAILevelSlider) { double toHeight = 0; int effectiveChildCount = 0; for (Node child : menuSubBox.getChildren()) { if (child.isVisible() && child != aiLevelTitleLabel && child != aiLevelSlider && child != aiLevelLabelPane) { toHeight = toHeight + child.getBoundsInParent().getHeight(); effectiveChildCount = effectiveChildCount + 1; }//from w w w. ja v a 2 s.c o m } if (includeAILevelSlider) { toHeight = toHeight + aiLevelLabelPane.getPrefHeight(); toHeight = toHeight + aiLevelSlider.getPrefHeight(); toHeight = toHeight + aiLevelTitleLabel.getPrefHeight(); effectiveChildCount = effectiveChildCount + 3; } toHeight = toHeight + menuSubBox.getSpacing() * (effectiveChildCount - 1); if (updateMenuHeightTimeline != null && updateMenuHeightTimeline.getStatus() == Animation.Status.RUNNING) { updateMenuHeightTimeline.stop(); } updateMenuHeightTimeline = new Timeline(); KeyValue keyValue0 = new KeyValue(menuSubBox.prefHeightProperty(), toHeight, Interpolator.EASE_BOTH); KeyFrame keyFrame0 = new KeyFrame(Duration.seconds(animationSpeed), keyValue0); updateMenuHeightTimeline.getKeyFrames().add(keyFrame0); updateMenuHeightTimeline.play(); }