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