Search in sources :

Example 1 with ParallelTransition

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

the class GameManager method moveTiles.

/**
     * Moves the tiles according to given direction
     * At any move, takes care of merge tiles, add a new one and perform the
     * required animations
     * It updates the score and checks if the user won the game or if the game is over 
     * 
     * @param direction is the selected direction to move the tiles
     */
private void moveTiles(Direction direction) {
    synchronized (gameGrid) {
        if (movingTiles) {
            return;
        }
    }
    board.setPoints(0);
    mergedToBeRemoved.clear();
    ParallelTransition parallelTransition = new ParallelTransition();
    gridOperator.sortGrid(direction);
    final int tilesWereMoved = gridOperator.traverseGrid((x, y) -> {
        Location thisloc = new Location(x, y);
        // farthest available location
        Location farthestLocation = findFarthestLocation(thisloc, direction);
        Optional<Tile> opTile = optionalTile(thisloc);
        AtomicInteger result = new AtomicInteger();
        // calculates to a possible merge
        Location nextLocation = farthestLocation.offset(direction);
        optionalTile(nextLocation).filter(t -> t.isMergeable(opTile) && !t.isMerged()).ifPresent(t -> {
            Tile tile = opTile.get();
            t.merge(tile);
            t.toFront();
            gameGrid.put(nextLocation, t);
            gameGrid.replace(thisloc, null);
            parallelTransition.getChildren().add(animateExistingTile(tile, t.getLocation()));
            parallelTransition.getChildren().add(animateMergedTile(t));
            mergedToBeRemoved.add(tile);
            board.addPoints(t.getValue());
            if (t.getValue() == FINAL_VALUE_TO_WIN) {
                board.setGameWin(true);
            }
            result.set(1);
        });
        if (result.get() == 0 && opTile.isPresent() && !farthestLocation.equals(thisloc)) {
            Tile tile = opTile.get();
            parallelTransition.getChildren().add(animateExistingTile(tile, farthestLocation));
            gameGrid.put(farthestLocation, tile);
            gameGrid.replace(thisloc, null);
            tile.setLocation(farthestLocation);
            result.set(1);
        }
        return result.get();
    });
    board.animateScore();
    if (parallelTransition.getChildren().size() > 0) {
        parallelTransition.setOnFinished(e -> {
            board.getGridGroup().getChildren().removeAll(mergedToBeRemoved);
            gameGrid.values().stream().filter(Objects::nonNull).forEach(Tile::clearMerge);
            Location randomAvailableLocation = findRandomAvailableLocation();
            if (randomAvailableLocation == null && mergeMovementsAvailable() == 0) {
                board.setGameOver(true);
            } else if (randomAvailableLocation != null && tilesWereMoved > 0) {
                synchronized (gameGrid) {
                    movingTiles = false;
                }
                addAndAnimateRandomTile(randomAvailableLocation);
            }
        });
        synchronized (gameGrid) {
            movingTiles = true;
        }
        parallelTransition.play();
    }
}
Also used : Arrays(java.util.Arrays) HashMap(java.util.HashMap) Random(java.util.Random) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) HostServices(javafx.application.HostServices) KeyValue(javafx.animation.KeyValue) HBox(javafx.scene.layout.HBox) KeyFrame(javafx.animation.KeyFrame) Iterator(java.util.Iterator) Set(java.util.Set) Timeline(javafx.animation.Timeline) Group(javafx.scene.Group) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ParallelTransition(javafx.animation.ParallelTransition) List(java.util.List) ScaleTransition(javafx.animation.ScaleTransition) BooleanProperty(javafx.beans.property.BooleanProperty) Duration(javafx.util.Duration) Stream(java.util.stream.Stream) Interpolator(javafx.animation.Interpolator) SequentialTransition(javafx.animation.SequentialTransition) Optional(java.util.Optional) Collections(java.util.Collections) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ParallelTransition(javafx.animation.ParallelTransition)

Example 2 with ParallelTransition

use of javafx.animation.ParallelTransition in project Board-Instrumentation-Framework by intel.

the class RadialBargraphSkin method fadeBackToInteractive.

private void fadeBackToInteractive() {
    FadeTransition fadeUnitOut = new FadeTransition(Duration.millis(425), unit);
    fadeUnitOut.setFromValue(1.0);
    fadeUnitOut.setToValue(0.0);
    FadeTransition fadeValueOut = new FadeTransition(Duration.millis(425), value);
    fadeValueOut.setFromValue(1.0);
    fadeValueOut.setToValue(0.0);
    PauseTransition pause = new PauseTransition(Duration.millis(50));
    FadeTransition fadeUnitIn = new FadeTransition(Duration.millis(425), unit);
    fadeUnitIn.setFromValue(0.0);
    fadeUnitIn.setToValue(1.0);
    FadeTransition fadeValueIn = new FadeTransition(Duration.millis(425), value);
    fadeValueIn.setFromValue(0.0);
    fadeValueIn.setToValue(1.0);
    ParallelTransition parallelIn = new ParallelTransition(fadeUnitIn, fadeValueIn);
    ParallelTransition parallelOut = new ParallelTransition(fadeUnitOut, fadeValueOut);
    parallelOut.setOnFinished(event -> {
        unit.setText("Interactive");
        value.setText("");
        resizeText();
    });
    SequentialTransition sequence = new SequentialTransition(parallelOut, pause, parallelIn);
    sequence.play();
}
Also used : SequentialTransition(javafx.animation.SequentialTransition) FadeTransition(javafx.animation.FadeTransition) PauseTransition(javafx.animation.PauseTransition) ParallelTransition(javafx.animation.ParallelTransition)

Example 3 with ParallelTransition

use of javafx.animation.ParallelTransition in project Board-Instrumentation-Framework by intel.

the class HeatControlSkin method fadeBack.

private void fadeBack() {
    FadeTransition fadeInfoTextOut = new FadeTransition(Duration.millis(425), infoText);
    fadeInfoTextOut.setFromValue(1.0);
    fadeInfoTextOut.setToValue(0.0);
    FadeTransition fadeValueOut = new FadeTransition(Duration.millis(425), value);
    fadeValueOut.setFromValue(1.0);
    fadeValueOut.setToValue(0.0);
    PauseTransition pause = new PauseTransition(Duration.millis(50));
    FadeTransition fadeInfoTextIn = new FadeTransition(Duration.millis(425), infoText);
    fadeInfoTextIn.setFromValue(0.0);
    fadeInfoTextIn.setToValue(1.0);
    FadeTransition fadeValueIn = new FadeTransition(Duration.millis(425), value);
    fadeValueIn.setFromValue(0.0);
    fadeValueIn.setToValue(1.0);
    ParallelTransition parallelIn = new ParallelTransition(fadeInfoTextIn, fadeValueIn);
    ParallelTransition parallelOut = new ParallelTransition(fadeInfoTextOut, fadeValueOut);
    parallelOut.setOnFinished(event -> {
        double currentValue = (valueIndicatorRotate.getAngle() + getSkinnable().getStartAngle() - 180) / angleStep + getSkinnable().getMinValue();
        value.setText(String.format(Locale.US, "%." + getSkinnable().getDecimals() + "f", currentValue));
        value.setTranslateX((size - value.getLayoutBounds().getWidth()) * 0.5);
        if (getSkinnable().getTarget() < getSkinnable().getValue()) {
            getSkinnable().setInfoText("COOLING");
        } else if (getSkinnable().getTarget() > getSkinnable().getValue()) {
            getSkinnable().setInfoText("HEATING");
        }
        resizeText();
        drawTickMarks(ticks);
        userAction = false;
    });
    SequentialTransition sequence = new SequentialTransition(parallelOut, pause, parallelIn);
    sequence.play();
}
Also used : SequentialTransition(javafx.animation.SequentialTransition) FadeTransition(javafx.animation.FadeTransition) PauseTransition(javafx.animation.PauseTransition) ParallelTransition(javafx.animation.ParallelTransition)

Example 4 with ParallelTransition

use of javafx.animation.ParallelTransition in project Board-Instrumentation-Framework by intel.

the class RadialMenu method click.

public void click(final RadialMenuItem CLICKED_ITEM) {
    List<Transition> transitions = new ArrayList<>(items.size() * 2);
    for (Parent node : items.keySet()) {
        if (items.get(node).equals(CLICKED_ITEM)) {
            // Add enlarge transition to selected item
            ScaleTransition enlargeItem = new ScaleTransition(Duration.millis(300), node);
            enlargeItem.setToX(5.0);
            enlargeItem.setToY(5.0);
            enlargeItem.setOnFinished(event -> {
                node.setScaleX(1.0);
                node.setScaleY(1.0);
            });
            transitions.add(enlargeItem);
        } else {
            // Add shrink transition to all other items
            ScaleTransition shrinkItem = new ScaleTransition(Duration.millis(300), node);
            shrinkItem.setToX(0.0);
            shrinkItem.setToY(0.0);
            transitions.add(shrinkItem);
        }
        // Add fade out transition to every node
        FadeTransition fadeOutItem = new FadeTransition(Duration.millis(300), node);
        fadeOutItem.setToValue(0.0);
        fadeOutItem.setOnFinished(event -> {
            node.setTranslateX(0);
            node.setTranslateY(0);
        });
        transitions.add(fadeOutItem);
    }
    // Add rotate and fade transition to main menu button
    if (options.isButtonHideOnSelect()) {
        RotateTransition rotateMainButton = new RotateTransition(Duration.millis(300), mainMenuButton);
        rotateMainButton.setToAngle(225);
        transitions.add(rotateMainButton);
        FadeTransition fadeOutMainButton = new FadeTransition(Duration.millis(300), mainMenuButton);
        fadeOutMainButton.setToValue(0.0);
        transitions.add(fadeOutMainButton);
        ScaleTransition shrinkMainButton = new ScaleTransition(Duration.millis(300), mainMenuButton);
        shrinkMainButton.setToX(0.0);
        shrinkMainButton.setToY(0.0);
        transitions.add(shrinkMainButton);
    } else {
        RotateTransition rotateBackMainButton = new RotateTransition();
        rotateBackMainButton.setNode(cross);
        rotateBackMainButton.setToAngle(0);
        rotateBackMainButton.setDuration(Duration.millis(200));
        rotateBackMainButton.setInterpolator(Interpolator.EASE_BOTH);
        transitions.add(rotateBackMainButton);
        FadeTransition mainButtonFadeOut = new FadeTransition();
        mainButtonFadeOut.setNode(mainMenuButton);
        mainButtonFadeOut.setDuration(Duration.millis(100));
        mainButtonFadeOut.setToValue(options.getButtonAlpha());
        transitions.add(mainButtonFadeOut);
    }
    // Play all transitions in parallel
    ParallelTransition selectTransition = new ParallelTransition();
    selectTransition.getChildren().addAll(transitions);
    selectTransition.play();
    // Set menu state back to closed
    setState(State.CLOSED);
    mainMenuButton.setOpen(false);
}
Also used : Parent(javafx.scene.Parent) FadeTransition(javafx.animation.FadeTransition) RotateTransition(javafx.animation.RotateTransition) Transition(javafx.animation.Transition) FadeTransition(javafx.animation.FadeTransition) RotateTransition(javafx.animation.RotateTransition) ParallelTransition(javafx.animation.ParallelTransition) ScaleTransition(javafx.animation.ScaleTransition) ArrayList(java.util.ArrayList) ScaleTransition(javafx.animation.ScaleTransition) ParallelTransition(javafx.animation.ParallelTransition)

Example 5 with ParallelTransition

use of javafx.animation.ParallelTransition in project latexdraw by arnobl.

the class Canvas method setZoom.

@Override
public void setZoom(final double x, final double y, final double z) {
    if (z <= getMaxZoom() && z >= getMinZoom() && !MathUtils.INST.equalsDouble(z, zoom.getValue())) {
        zoom.setValue(z);
        final Duration duration = Duration.millis(250);
        final ParallelTransition parallelTransition = new ParallelTransition();
        parallelTransition.getChildren().addAll(new Timeline(new KeyFrame(duration, new KeyValue(scaleYProperty(), z))), new Timeline(new KeyFrame(duration, new KeyValue(scaleXProperty(), z))));
        parallelTransition.play();
        setModified(true);
    }
}
Also used : Timeline(javafx.animation.Timeline) KeyValue(javafx.animation.KeyValue) KeyFrame(javafx.animation.KeyFrame) Duration(javafx.util.Duration) ParallelTransition(javafx.animation.ParallelTransition)

Aggregations

ParallelTransition (javafx.animation.ParallelTransition)11 KeyFrame (javafx.animation.KeyFrame)5 KeyValue (javafx.animation.KeyValue)5 SequentialTransition (javafx.animation.SequentialTransition)5 Timeline (javafx.animation.Timeline)5 FadeTransition (javafx.animation.FadeTransition)4 PauseTransition (javafx.animation.PauseTransition)4 Duration (javafx.util.Duration)4 ArrayList (java.util.ArrayList)3 Interpolator (javafx.animation.Interpolator)3 RotateTransition (javafx.animation.RotateTransition)3 HashMap (java.util.HashMap)2 List (java.util.List)2 FillTransition (javafx.animation.FillTransition)2 ScaleTransition (javafx.animation.ScaleTransition)2 Transition (javafx.animation.Transition)2 Group (javafx.scene.Group)2 Node (javafx.scene.Node)2 JFXAutoCompletePopup (com.jfoenix.controls.JFXAutoCompletePopup)1 JFXAutoCompleteEvent (com.jfoenix.controls.events.JFXAutoCompleteEvent)1