2014-06-06 65 views
0

我複製從互聯網上這是一個類似於上official JavaFX sample page發現了一些代碼:爲什麼我的JavaFX PathTransition不可見?

final Rectangle rectPath = new Rectangle (0, 0, 40, 40); 
rectPath.setArcHeight(10); 
rectPath.setArcWidth(10); 
rectPath.setFill(Color.ORANGE); 
Path path = new Path(); 
path.getElements().add(new MoveTo(20,20)); 
path.getElements().add(new CubicCurveTo(380, 0, 380, 120, 200, 120)); 
path.getElements().add(new CubicCurveTo(0, 120, 0, 240, 380, 240)); 
PathTransition pathTransition = new PathTransition(); 
pathTransition.setDuration(Duration.millis(4000)); 
pathTransition.setPath(path); 
pathTransition.setNode(rectPath); 
pathTransition.setOrientation(PathTransition.OrientationType.ORTHOGONAL_TO_TANGENT); 
pathTransition.setCycleCount(Timeline.INDEFINITE); 
pathTransition.setAutoReverse(true); 
pathTransition.play(); 
// add the path to a pane: 
myPane.getChildren().add(path); 

現在我得到的是人的路,但沒有漂浮矩形:

我有什麼爲了使可視化進行到真正的遊戲?

回答

0

您需要將您的矩形(rectPath)添加到您的場景,或者你不會看到它:

myPane.getChildren().add(path, rectPath);