progress with the rotation system but still not finished , it works tho
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
49d2c5d7ab
commit
5911d88918
@ -1,10 +1,17 @@
|
|||||||
package application;
|
package application;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
|
import javafx.event.Event;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
import javafx.scene.Group;
|
import javafx.scene.Group;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.input.KeyEvent;
|
||||||
|
import javafx.scene.input.KeyCode;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.shape.Polygon;
|
import javafx.scene.shape.Polygon;
|
||||||
|
import javafx.scene.transform.Rotate;
|
||||||
|
import javafx.animation.RotateTransition;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
import javafx.util.Duration;
|
||||||
public class Piece extends Application{
|
public class Piece extends Application{
|
||||||
|
|
||||||
public void start(Stage primaryStage) throws Exception {
|
public void start(Stage primaryStage) throws Exception {
|
||||||
@ -18,15 +25,54 @@ public class Piece extends Application{
|
|||||||
100.0,100.0,
|
100.0,100.0,
|
||||||
0.0,100.0});
|
0.0,100.0});
|
||||||
|
|
||||||
piece1.setFill(Color.LIMEGREEN);
|
|
||||||
piece1.setStroke(Color.BLACK);
|
|
||||||
|
|
||||||
Group root = new Group();
|
Group root = new Group();
|
||||||
root.getChildren().addAll(piece1);
|
root.getChildren().addAll(piece1);
|
||||||
Scene scene = new Scene(root,490,450,Color.WHEAT);
|
Scene scene = new Scene(root,490,450,Color.WHEAT);
|
||||||
primaryStage.setScene(scene);
|
primaryStage.setScene(scene);
|
||||||
primaryStage.setTitle("piece 1");
|
primaryStage.setTitle("piece 1");
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
piece1.setFill(Color.LIMEGREEN);
|
||||||
|
piece1.setStroke(Color.BLACK);
|
||||||
|
piece1.setStrokeWidth(3);
|
||||||
|
|
||||||
|
|
||||||
|
//Instantiating RotateTransition class to create the animation (rotation to the right)
|
||||||
|
RotateTransition rotaterght = new RotateTransition();
|
||||||
|
//setting attributes for the RotateTransition
|
||||||
|
rotaterght.setByAngle(90);
|
||||||
|
rotaterght.autoReverseProperty();
|
||||||
|
rotaterght.setDuration(Duration.millis(1000));
|
||||||
|
rotaterght.setNode(piece1);
|
||||||
|
rotaterght.setAxis(Rotate.Z_AXIS);
|
||||||
|
|
||||||
|
//Instantiating RotateTransition class to create the animation (rotation to the left)
|
||||||
|
RotateTransition rotatelft = new RotateTransition();
|
||||||
|
//setting attributes for the RotateTransition
|
||||||
|
rotatelft.setByAngle(-90);
|
||||||
|
rotatelft.autoReverseProperty();
|
||||||
|
rotatelft.setDuration(Duration.millis(1000));
|
||||||
|
rotatelft.setNode(piece1);
|
||||||
|
rotatelft.setAxis(Rotate.Z_AXIS);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
|
||||||
|
|
||||||
|
public void handle(KeyEvent event) {// 'event' means corresponds to clicking on the clipboard
|
||||||
|
switch (event.getCode()) {// 'getCode' gets the code of the key pressed on the clipboard
|
||||||
|
case RIGHT: rotaterght.play(); break;
|
||||||
|
case LEFT: rotatelft.play(); break;
|
||||||
|
default: System.out.println("this case hasn't been taken in charge yet");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
Loading…
Reference in New Issue
Block a user