It seems that when I move the circle outside the group of squares, it moves the squares even though there is no code that does that. I'm 99% percent sure it is because the group is trying to auto center itself, but it only does it if I change the scale of the group. Here is the code that demonstrates the problem I'm currently having.(Note that I don't want the square to move at all)
import javafx.application.Application;
import javafx.scene.shape.Circle;
import javafx.animation.Timeline;
import javafx.animation.KeyFrame;
import javafx.util.Duration;
import javafx.scene.layout.Pane;
import javafx.scene.Scene;
import javafx.event.EventHandler;
import javafx.event.ActionEvent;
import javafx.scene.Group;
import javafx.stage.Stage;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
public class Test extends Application
{
private static Circle circle = new Circle(0, 0, 10);
private static Group group = new Group(circle);
private static Group mainPane = new Group(group);
private Scene scene = new Scene(mainPane, 600, 600);
public void start(Stage stage){
circle.setViewOrder(-1);
for(int i = 0; i < 100; i++){
Rectangle backGround = new Rectangle(-10, -10, 20, 20);
backGround.setLayoutX((i - (int)(i * .1) * 10) * 20 - 100);
backGround.setLayoutY((int)(i * .1) * 20 - 100);
group.getChildren().add(backGround);
}
/*This line causes the problem*/group.setScaleX(1.5);
/*This line causes the problem*/group.setScaleY(1.5);
group.setLayoutX(200);
group.setLayoutY(200);
circle.setFill(Color.RED);
Timeline time = new Timeline();
time.setCycleCount(Timeline.INDEFINITE);
KeyFrame frame = new KeyFrame(Duration.millis(1), new EventHandler<ActionEvent>(){
@Override public void handle(ActionEvent e){
circle.setLayoutX(circle.getLayoutX() + .1);
if(circle.getLayoutX() > 150) circle.setLayoutX(0);
}
});
time.getKeyFrames().add(frame);
time.playFromStart();
stage.setScene(scene);
stage.show();
}
}