OrangeBlock是一个橙色的块,里面有文字.它实现为StackPane包含矩形顶部的文本.(这种方法在StackPane的文档中得到了证明.)
我已经放置了一个OrangeBlock坐标(100,80),现在我正试图让它平稳地移动到一些目标坐标.不幸的是,我在路上遇到了一个令人讨厌的问题:

由于某种原因,PathElements中的坐标相对于橙色块进行解释.
为什么是这样?我怎样才能OrangeBlock沿着绝对坐标的路径前行?下面的最小工作示例.
import javafx.animation.PathTransition;
import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.*;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.util.Duration;
public class PathTransitionExample extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Group root = new Group();
OrangeBlock block = new OrangeBlock(60, 40);
block.relocate(100, 80);
root.getChildren().add(block);
PathTransition transition = newPathTransitionTo(block, 460, 320);
primaryStage.setScene(new Scene(root, 600, 400));
primaryStage.show();
transition.play();
}
private static PathTransition newPathTransitionTo(OrangeBlock …Run Code Online (Sandbox Code Playgroud) javafx ×1