Commits

Anonymous committed c5858d3

- Fixed jittery vector enemy

Comments (0)

Files changed (1)

defender/src/main/java/com/fxexperience/games/defender/enemies/VectorEnemy.java

 import javafx.beans.value.ObservableValue;
 import javafx.event.ActionEvent;
 import javafx.event.EventHandler;
+import javafx.scene.Group;
+import javafx.scene.GroupBuilder;
+import javafx.scene.layout.Pane;
+import javafx.scene.layout.PaneBuilder;
+import javafx.scene.layout.StackPane;
+import javafx.scene.layout.StackPaneBuilder;
 import javafx.scene.paint.Color;
 import javafx.scene.shape.*;
 import javafx.scene.transform.Rotate;
     public VectorEnemy() {
         super(300, 40);
         final int radius = 25;
+        int pad = 6;
+        Pane stackPane = PaneBuilder.create().prefHeight(radius * 2 + pad).prefWidth(radius * 2 + pad).build();
+        getChildren().add(stackPane);
+        Group group = GroupBuilder.create().translateX(pad/2).translateY(pad/2).build();
+        stackPane.getChildren().add(group);
         int numLines = 5;
         int strokeWidth = 1;
         Color color = Color.PURPLE;
         Circle circle = CircleBuilder.create().radius(radius).centerX(radius).centerY(radius).fill(null).stroke(color).strokeWidth(strokeWidth).build();
-        getChildren().add(circle);
-
+        group.getChildren().add(circle);
         final ParallelTransition allRotateTransitions = new ParallelTransition();
 
         int currentAngle = 0;
             line.setTranslateX(radius);
             line.setTranslateY(radius);
             line.setStroke(color);
-            this.getChildren().add(line);
+            group.getChildren().add(line);
 
             Rotate rotate = new Rotate(currentAngle);
-            currentAngle += 360/numLines;
+            currentAngle += 360 / numLines;
             line.getTransforms().add(rotate);
         }
         this.lifeProperty().addListener(new ChangeListener<Number>() {