added animation when switching scenes
parent
6ca85066db
commit
d207ebff19
|
@ -1,13 +1,19 @@
|
|||
package latice.controller;
|
||||
|
||||
import javafx.animation.Interpolator;
|
||||
import javafx.animation.KeyFrame;
|
||||
import javafx.animation.KeyValue;
|
||||
import javafx.animation.Timeline;
|
||||
import javafx.application.Platform;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.shape.Rectangle;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.util.Duration;
|
||||
import latice.application.LaticeApplicationWindow;
|
||||
|
||||
public class MainScreenController extends LaticeApplicationWindow{
|
||||
|
@ -17,6 +23,10 @@ public class MainScreenController extends LaticeApplicationWindow{
|
|||
private Rectangle rulesButton;
|
||||
@FXML
|
||||
private Rectangle exitButton;
|
||||
@FXML
|
||||
private StackPane parentStackPane;
|
||||
@FXML
|
||||
private BorderPane menuBorderPane;
|
||||
|
||||
// Event Listener on Rectangle[#playButton].onMouseClicked
|
||||
@FXML
|
||||
|
@ -24,8 +34,20 @@ public class MainScreenController extends LaticeApplicationWindow{
|
|||
System.out.println("playButtonClicked");
|
||||
Stage stage = (Stage) ((Node) event.getTarget()).getScene().getWindow();
|
||||
StackPane root = getRootLayout();
|
||||
Scene scene = new Scene(root, 1280, 720);
|
||||
stage.setScene(scene);
|
||||
root.translateYProperty().set(stage.getHeight());
|
||||
parentStackPane.getChildren().add(root);
|
||||
|
||||
//parameters of the animation
|
||||
Timeline timeline = new Timeline();
|
||||
KeyValue kv = new KeyValue(root.translateYProperty(), 0, Interpolator.EASE_IN);
|
||||
KeyFrame kf = new KeyFrame(Duration.seconds(1), kv);
|
||||
timeline.getKeyFrames().add(kf);
|
||||
|
||||
//when the animation is finished we're removing the main screen
|
||||
timeline.setOnFinished(t -> {
|
||||
parentStackPane.getChildren().remove(menuBorderPane);
|
||||
});
|
||||
timeline.play();
|
||||
}
|
||||
// Event Listener on Rectangle[#rulesButton].onMouseClicked
|
||||
@FXML
|
||||
|
|
|
@ -4,9 +4,13 @@
|
|||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.BorderPane?>
|
||||
<?import javafx.scene.layout.Pane?>
|
||||
<?import javafx.scene.layout.StackPane?>
|
||||
<?import javafx.scene.shape.Rectangle?>
|
||||
|
||||
<BorderPane prefHeight="720.0" prefWidth="1280.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="latice.controller.MainScreenController">
|
||||
|
||||
<StackPane fx:id="parentStackPane" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="latice.controller.MainScreenController">
|
||||
<children>
|
||||
<BorderPane fx:id="menuBorderPane" prefHeight="720.0" prefWidth="1280.0">
|
||||
<center>
|
||||
<Pane prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||
<children>
|
||||
|
@ -18,6 +22,9 @@
|
|||
<Rectangle fx:id="playButton" arcHeight="5.0" arcWidth="5.0" fill="TRANSPARENT" height="151.0" layoutX="345.0" layoutY="175.0" onMouseClicked="#playButtonClicked" stroke="TRANSPARENT" strokeType="INSIDE" width="582.0" />
|
||||
<Rectangle fx:id="rulesButton" arcHeight="5.0" arcWidth="5.0" fill="#1f93ff00" height="152.0" layoutX="346.0" layoutY="355.0" onMouseClicked="#rulesButtonClicked" stroke="TRANSPARENT" strokeType="INSIDE" width="585.0" />
|
||||
<Rectangle fx:id="exitButton" arcHeight="5.0" arcWidth="5.0" fill="#1f93ff00" height="152.0" layoutX="348.0" layoutY="535.0" onMouseClicked="#exitButtonClicked" stroke="TRANSPARENT" strokeType="INSIDE" width="583.0" />
|
||||
</children></Pane>
|
||||
</children>
|
||||
</Pane>
|
||||
</center>
|
||||
</BorderPane>
|
||||
</BorderPane>
|
||||
</children>
|
||||
</StackPane>
|
||||
|
|
Loading…
Reference in New Issue