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();
}
}
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();
}
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();
}
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);
}
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);
}
}
Aggregations