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