Search in sources :

Example 96 with KeyFrame

use of javafx.animation.KeyFrame in project Gargoyle by callakrsos.

the class CameraTransformer method transitionCameraTo.

public void transitionCameraTo(double milliseconds, double tx, double ty, double tz, double rx, double ry, double rz) {
    final Timeline timeline = new Timeline();
    timeline.getKeyFrames().addAll(new KeyFrame[] { new KeyFrame(Duration.millis(milliseconds), new KeyValue[] { // Frame End                 
    new KeyValue(xRotateProperty(), rx, Interpolator.EASE_BOTH), new KeyValue(yRotateProperty(), ry, Interpolator.EASE_BOTH), new KeyValue(zRotateProperty(), rz, Interpolator.EASE_BOTH), new KeyValue(xTranslateProperty(), tx, Interpolator.EASE_BOTH), new KeyValue(yTranslateProperty(), ty, Interpolator.EASE_BOTH), new KeyValue(zTranslateProperty(), tz, Interpolator.EASE_BOTH) }) });
    timeline.playFromStart();
}
Also used : Timeline(javafx.animation.Timeline) KeyValue(javafx.animation.KeyValue) KeyFrame(javafx.animation.KeyFrame)

Example 97 with KeyFrame

use of javafx.animation.KeyFrame in project fx2048 by brunoborges.

the class Board method initGameProperties.

private void initGameProperties() {
    overlay.setMinSize(gridWidth, gridWidth);
    overlay.setAlignment(Pos.CENTER);
    overlay.setTranslateY(TOP_HEIGHT + GAP_HEIGHT);
    overlay.getChildren().setAll(txtOverlay);
    txtOverlay.setAlignment(Pos.CENTER);
    buttonsOverlay.setAlignment(Pos.CENTER);
    buttonsOverlay.setTranslateY(TOP_HEIGHT + GAP_HEIGHT + gridWidth / 2);
    buttonsOverlay.setMinSize(gridWidth, gridWidth / 2);
    buttonsOverlay.setSpacing(10);
    bTry.getStyleClass().add("game-button");
    bTry.setOnTouchPressed(e -> btnTryAgain());
    bTry.setOnAction(e -> btnTryAgain());
    bTry.setOnKeyPressed(e -> {
        if (e.getCode().equals(KeyCode.ENTER) || e.getCode().equals(KeyCode.SPACE)) {
            btnTryAgain();
        }
    });
    bContinue.getStyleClass().add("game-button");
    bContinue.setOnTouchPressed(e -> keepGoing());
    bContinue.setOnMouseClicked(e -> keepGoing());
    bContinue.setOnKeyPressed(e -> {
        if (e.getCode().equals(KeyCode.ENTER) || e.getCode().equals(KeyCode.SPACE)) {
            keepGoing();
        }
    });
    bContinueNo.getStyleClass().add("game-button");
    bContinueNo.setOnTouchPressed(e -> keepGoing());
    bContinueNo.setOnMouseClicked(e -> keepGoing());
    bContinueNo.setOnKeyPressed(e -> {
        if (e.getCode().equals(KeyCode.ENTER) || e.getCode().equals(KeyCode.SPACE)) {
            keepGoing();
        }
    });
    bSave.getStyleClass().add("game-button");
    bSave.setOnTouchPressed(e -> saveGame.set(true));
    bSave.setOnMouseClicked(e -> saveGame.set(true));
    bSave.setOnKeyPressed(e -> {
        if (e.getCode().equals(KeyCode.ENTER) || e.getCode().equals(KeyCode.SPACE)) {
            saveGame.set(true);
        }
    });
    bRestore.getStyleClass().add("game-button");
    bRestore.setOnTouchPressed(e -> restoreGame.set(true));
    bRestore.setOnMouseClicked(e -> restoreGame.set(true));
    bRestore.setOnKeyPressed(e -> {
        if (e.getCode().equals(KeyCode.ENTER) || e.getCode().equals(KeyCode.SPACE)) {
            restoreGame.set(true);
        }
    });
    bQuit.getStyleClass().add("game-button");
    bQuit.setOnTouchPressed(e -> quit());
    bQuit.setOnMouseClicked(e -> quit());
    bQuit.setOnKeyPressed(e -> {
        if (e.getCode().equals(KeyCode.ENTER) || e.getCode().equals(KeyCode.SPACE)) {
            quit();
        }
    });
    timerPause = new Timeline(new KeyFrame(Duration.seconds(1), e -> time = time.plusNanos(1_000_000_000)));
    timerPause.setCycleCount(Animation.INDEFINITE);
    gameWonProperty.addListener(wonListener);
    gameOverProperty.addListener(new Overlay("Game over!", "", bTry, null, "game-overlay-over", "game-lblOver", false));
    gamePauseProperty.addListener(new Overlay("Game Paused", "", bContinue, null, "game-overlay-pause", "game-lblPause", true));
    gameTryAgainProperty.addListener(new Overlay("Try Again?", "Current game will be deleted", bTry, bContinueNo, "game-overlay-pause", "game-lblPause", true));
    gameSaveProperty.addListener(new Overlay("Save?", "Previous saved data will be overwritten", bSave, bContinueNo, "game-overlay-pause", "game-lblPause", true));
    gameRestoreProperty.addListener(new Overlay("Restore?", "Current game will be deleted", bRestore, bContinueNo, "game-overlay-pause", "game-lblPause", true));
    gameAboutProperty.addListener((observable, oldValue, newValue) -> {
        if (newValue) {
            timer.stop();
            timerPause.play();
            overlay.getStyleClass().setAll("game-overlay", "game-overlay-quit");
            TextFlow flow = new TextFlow();
            flow.setTextAlignment(TextAlignment.CENTER);
            flow.setPadding(new Insets(10, 0, 0, 0));
            flow.setMinSize(gridWidth, gridWidth);
            flow.setPrefSize(gridWidth, gridWidth);
            flow.setMaxSize(gridWidth, gridWidth);
            flow.setPrefSize(BASELINE_OFFSET_SAME_AS_HEIGHT, BASELINE_OFFSET_SAME_AS_HEIGHT);
            Text t00 = new Text("2048");
            t00.getStyleClass().setAll("game-label", "game-lblAbout");
            Text t01 = new Text("FX");
            t01.getStyleClass().setAll("game-label", "game-lblAbout2");
            Text t02 = new Text(" Game\n");
            t02.getStyleClass().setAll("game-label", "game-lblAbout");
            Text t1 = new Text("JavaFX game - Desktop version\n\n");
            t1.getStyleClass().setAll("game-label", "game-lblAboutSub");
            Text t20 = new Text("Powered by ");
            t20.getStyleClass().setAll("game-label", "game-lblAboutSub");
            Hyperlink link1 = new Hyperlink();
            link1.setText("JavaFXPorts");
            link1.setOnAction(e -> hostServices.showDocument("http://javafxports.org/page/home"));
            link1.getStyleClass().setAll("game-label", "game-lblAboutSub2");
            Text t21 = new Text(" Project \n\n");
            t21.getStyleClass().setAll("game-label", "game-lblAboutSub");
            Text t23 = new Text("© ");
            t23.getStyleClass().setAll("game-label", "game-lblAboutSub");
            Hyperlink link2 = new Hyperlink();
            link2.setText("@JPeredaDnr");
            link2.setOnAction(e -> hostServices.showDocument("https://twitter.com/JPeredaDnr"));
            link2.getStyleClass().setAll("game-label", "game-lblAboutSub2");
            Text t22 = new Text(" & ");
            t22.getStyleClass().setAll("game-label", "game-lblAboutSub");
            Hyperlink link3 = new Hyperlink();
            link3.setText("@brunoborges");
            link3.setOnAction(e -> hostServices.showDocument("https://twitter.com/brunoborges"));
            Text t32 = new Text(" & ");
            t32.getStyleClass().setAll("game-label", "game-lblAboutSub");
            link3.getStyleClass().setAll("game-label", "game-lblAboutSub2");
            Text t24 = new Text("\n\n");
            t24.getStyleClass().setAll("game-label", "game-lblAboutSub");
            Text t31 = new Text(" Version " + Game2048.VERSION + " - 2015\n\n");
            t31.getStyleClass().setAll("game-label", "game-lblAboutSub");
            flow.getChildren().setAll(t00, t01, t02, t1, t20, link1, t21, t23, link2, t22, link3);
            flow.getChildren().addAll(t24, t31);
            txtOverlay.getChildren().setAll(flow);
            buttonsOverlay.getChildren().setAll(bContinue);
            this.getChildren().removeAll(overlay, buttonsOverlay);
            this.getChildren().addAll(overlay, buttonsOverlay);
            layerOnProperty.set(true);
        }
    });
    gameQuitProperty.addListener(new Overlay("Quit Game?", "Non saved data will be lost", bQuit, bContinueNo, "game-overlay-quit", "game-lblQuit", true));
    restoreRecord();
    gameScoreProperty.addListener((ov, i, i1) -> {
        if (i1.intValue() > gameBestProperty.get()) {
            gameBestProperty.set(i1.intValue());
        }
    });
    layerOnProperty.addListener((ov, b, b1) -> {
        if (!b1) {
            getChildren().removeAll(overlay, buttonsOverlay);
            // Keep the focus on the game when the layer is removed:
            getParent().requestFocus();
        } else if (b1) {
            // Set focus on the first button
            buttonsOverlay.getChildren().get(0).requestFocus();
        }
    });
}
Also used : Timeline(javafx.animation.Timeline) Insets(javafx.geometry.Insets) KeyFrame(javafx.animation.KeyFrame) TextFlow(javafx.scene.text.TextFlow) Text(javafx.scene.text.Text) Hyperlink(javafx.scene.control.Hyperlink)

Example 98 with KeyFrame

use of javafx.animation.KeyFrame in project fx2048 by brunoborges.

the class GameManager method animateExistingTile.

/**
     * Animation that moves the tile from its previous location to a new location 
     * @param tile to be animated
     * @param newLocation new location of the tile
     * @return a timeline 
     */
private Timeline animateExistingTile(Tile tile, Location newLocation) {
    Timeline timeline = new Timeline();
    KeyValue kvX = new KeyValue(tile.layoutXProperty(), newLocation.getLayoutX(Board.CELL_SIZE) - (tile.getMinHeight() / 2), Interpolator.EASE_OUT);
    KeyValue kvY = new KeyValue(tile.layoutYProperty(), newLocation.getLayoutY(Board.CELL_SIZE) - (tile.getMinHeight() / 2), Interpolator.EASE_OUT);
    KeyFrame kfX = new KeyFrame(ANIMATION_EXISTING_TILE, kvX);
    KeyFrame kfY = new KeyFrame(ANIMATION_EXISTING_TILE, kvY);
    timeline.getKeyFrames().add(kfX);
    timeline.getKeyFrames().add(kfY);
    return timeline;
}
Also used : Timeline(javafx.animation.Timeline) KeyValue(javafx.animation.KeyValue) KeyFrame(javafx.animation.KeyFrame)

Example 99 with KeyFrame

use of javafx.animation.KeyFrame in project Gargoyle by callakrsos.

the class DockTabPaneSkin method createTimeline.

private Timeline createTimeline(final TabHeaderSkin tabRegion, final Duration duration, final double endValue, final EventHandler<ActionEvent> func) {
    Timeline timeline = new Timeline();
    timeline.setCycleCount(1);
    KeyValue keyValue = new KeyValue(tabRegion.animationTransition, endValue, Interpolator.LINEAR);
    timeline.getKeyFrames().clear();
    timeline.getKeyFrames().add(new KeyFrame(duration, keyValue));
    timeline.setOnFinished(func);
    return timeline;
}
Also used : Timeline(javafx.animation.Timeline) KeyValue(javafx.animation.KeyValue) KeyFrame(javafx.animation.KeyFrame)

Example 100 with KeyFrame

use of javafx.animation.KeyFrame in project bitsquare by bitsquare.

the class PeerInfoWithTagEditor method animateHide.

@Override
protected void animateHide(Runnable onFinishedHandler) {
    if (Preferences.INSTANCE.getUseAnimations()) {
        double duration = getDuration(300);
        Interpolator interpolator = Interpolator.SPLINE(0.25, 0.1, 0.25, 1);
        gridPane.setRotationAxis(Rotate.X_AXIS);
        Camera camera = gridPane.getScene().getCamera();
        gridPane.getScene().setCamera(new PerspectiveCamera());
        Timeline timeline = new Timeline();
        ObservableList<KeyFrame> keyFrames = timeline.getKeyFrames();
        keyFrames.add(new KeyFrame(Duration.millis(0), new KeyValue(gridPane.rotateProperty(), 0, interpolator), new KeyValue(gridPane.opacityProperty(), 1, interpolator)));
        keyFrames.add(new KeyFrame(Duration.millis(duration), new KeyValue(gridPane.rotateProperty(), -90, interpolator), new KeyValue(gridPane.opacityProperty(), 0, interpolator)));
        timeline.setOnFinished(event -> {
            gridPane.setRotate(0);
            gridPane.setRotationAxis(Rotate.Z_AXIS);
            gridPane.getScene().setCamera(camera);
            onFinishedHandler.run();
        });
        timeline.play();
    } else {
        onFinishedHandler.run();
    }
}
Also used : Timeline(javafx.animation.Timeline) KeyValue(javafx.animation.KeyValue) KeyFrame(javafx.animation.KeyFrame) Interpolator(javafx.animation.Interpolator) PerspectiveCamera(javafx.scene.PerspectiveCamera) Camera(javafx.scene.Camera) PerspectiveCamera(javafx.scene.PerspectiveCamera)

Aggregations

KeyFrame (javafx.animation.KeyFrame)108 Timeline (javafx.animation.Timeline)107 KeyValue (javafx.animation.KeyValue)82 Duration (javafx.util.Duration)32 ActionEvent (javafx.event.ActionEvent)21 JFXButton (com.jfoenix.controls.JFXButton)20 IOException (java.io.IOException)19 URL (java.net.URL)19 ResourceBundle (java.util.ResourceBundle)19 FXML (javafx.fxml.FXML)19 Initializable (javafx.fxml.Initializable)18 FXMLLoader (javafx.fxml.FXMLLoader)17 AnchorPane (javafx.scene.layout.AnchorPane)16 Pane (javafx.scene.layout.Pane)16 Level (java.util.logging.Level)15 Logger (java.util.logging.Logger)15 MouseEvent (javafx.scene.input.MouseEvent)13 Rotate (javafx.scene.transform.Rotate)13 JFXTextField (com.jfoenix.controls.JFXTextField)12 Interpolator (javafx.animation.Interpolator)12