Search in sources :

Example 1 with RotateTransition

use of javafx.animation.RotateTransition in project Minesweeper3D by SethDamiani.

the class Main method createCube.

private void createCube(Group cubeGroup, Group gX, Group gY, Scene scene, Stage stage) {
    cubeGroup.setTranslateZ(-200);
    sideB.setTranslateX(200);
    sideB.setTranslateZ(200);
    sideB.setRotationAxis(new Point3D(0, 1, 0));
    sideB.setRotate(90);
    sideC.setTranslateZ(200);
    sideC.setTranslateX(-200);
    sideC.setRotationAxis(new Point3D(0, 1, 0));
    sideC.setRotate(90);
    sideD.setTranslateZ(400);
    sideE.setRotationAxis(new Point3D(1, 0, 0));
    sideE.setRotate(90);
    sideE.setTranslateY(200);
    sideE.setTranslateZ(200);
    sideF.setRotationAxis(new Point3D(1, 0, 0));
    sideF.setRotate(90);
    sideF.setTranslateY(-200);
    sideF.setTranslateZ(200);
    RotateTransition rightRotate = new RotateTransition(Duration.millis(10000), gY);
    rightRotate.setAxis(Rotate.Y_AXIS);
    rightRotate.setByAngle(-1000);
    rightRotate.setInterpolator(Interpolator.LINEAR);
    RotateTransition leftRotate = new RotateTransition(Duration.millis(10000), gY);
    leftRotate.setAxis(Rotate.Y_AXIS);
    leftRotate.setByAngle(1000);
    leftRotate.setInterpolator(Interpolator.LINEAR);
    RotateTransition upRotate = new RotateTransition(Duration.millis(10000), gX);
    upRotate.setAxis(Rotate.X_AXIS);
    upRotate.setByAngle(-1000);
    upRotate.setInterpolator(Interpolator.LINEAR);
    RotateTransition downRotate = new RotateTransition(Duration.millis(10000), gX);
    downRotate.setAxis(Rotate.X_AXIS);
    downRotate.setByAngle(1000);
    downRotate.setInterpolator(Interpolator.LINEAR);
    EventHandler<KeyEvent> KeyPressHandler = event -> {
        if (event.getCode() == KeyCode.ESCAPE) {
            timeTask.pause();
            stage.setScene(confirmExit);
        } else if (event.getCode() == KeyCode.D || event.getCode() == KeyCode.RIGHT)
            rightRotate.play();
        else if (event.getCode() == KeyCode.A || event.getCode() == KeyCode.LEFT)
            leftRotate.play();
        else if (event.getCode() == KeyCode.W || event.getCode() == KeyCode.UP)
            upRotate.play();
        else if (event.getCode() == KeyCode.S || event.getCode() == KeyCode.DOWN)
            downRotate.play();
    };
    scene.addEventHandler(KeyEvent.KEY_PRESSED, KeyPressHandler);
    EventHandler<KeyEvent> KeyReleaseHandler = event -> {
        if (event.getCode() == KeyCode.D || event.getCode() == KeyCode.RIGHT)
            rightRotate.stop();
        else if (event.getCode() == KeyCode.A || event.getCode() == KeyCode.LEFT)
            leftRotate.stop();
        else if (event.getCode() == KeyCode.W || event.getCode() == KeyCode.UP)
            upRotate.stop();
        else if (event.getCode() == KeyCode.S || event.getCode() == KeyCode.DOWN)
            downRotate.stop();
    };
    scene.addEventHandler(KeyEvent.KEY_RELEASED, KeyReleaseHandler);
}
Also used : EventHandler(javafx.event.EventHandler) FontWeight(javafx.scene.text.FontWeight) Scene(javafx.scene.Scene) MouseButton(javafx.scene.input.MouseButton) java.util(java.util) Point3D(javafx.geometry.Point3D) javafx.scene.control(javafx.scene.control) Rotate(javafx.scene.transform.Rotate) MouseEvent(javafx.scene.input.MouseEvent) FXCollections(javafx.collections.FXCollections) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) Application(javafx.application.Application) TextAlignment(javafx.scene.text.TextAlignment) RotateTransition(javafx.animation.RotateTransition) PrintWriter(java.io.PrintWriter) KeyCode(javafx.scene.input.KeyCode) HBox(javafx.scene.layout.HBox) Color(javafx.scene.paint.Color) KeyFrame(javafx.animation.KeyFrame) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) Font(javafx.scene.text.Font) FileWriter(java.io.FileWriter) Timeline(javafx.animation.Timeline) ImagePattern(javafx.scene.paint.ImagePattern) Rectangle(javafx.scene.shape.Rectangle) IOException(java.io.IOException) KeyEvent(javafx.scene.input.KeyEvent) Group(javafx.scene.Group) File(java.io.File) Text(javafx.scene.text.Text) Duration(javafx.util.Duration) Interpolator(javafx.animation.Interpolator) Stage(javafx.stage.Stage) ObservableList(javafx.collections.ObservableList) Image(javafx.scene.image.Image) KeyEvent(javafx.scene.input.KeyEvent) Point3D(javafx.geometry.Point3D) RotateTransition(javafx.animation.RotateTransition)

Aggregations

File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 java.util (java.util)1 Interpolator (javafx.animation.Interpolator)1 KeyFrame (javafx.animation.KeyFrame)1 RotateTransition (javafx.animation.RotateTransition)1 Timeline (javafx.animation.Timeline)1 Application (javafx.application.Application)1 FXCollections (javafx.collections.FXCollections)1 ObservableList (javafx.collections.ObservableList)1 EventHandler (javafx.event.EventHandler)1 Point3D (javafx.geometry.Point3D)1 Group (javafx.scene.Group)1 Scene (javafx.scene.Scene)1 javafx.scene.control (javafx.scene.control)1 PropertyValueFactory (javafx.scene.control.cell.PropertyValueFactory)1 TextFieldTableCell (javafx.scene.control.cell.TextFieldTableCell)1 Image (javafx.scene.image.Image)1