0

我在 javafx 中绘制时间线动画。这是创建行的代码:

    public Line getLine() {

Point startPoint = FigureUtil.translateGeographicalToViewCoords(center.longitude, center.latitude, mapViewState);
line = new Line();
line.setStartX(startPoint.x);
line.setStartY(startPoint.y);
line.setStrokeWidth(4);

line.setStyle("-fx-stroke: rgba(37, 176, 79, 0.5);");
return line;
}

public void stop(){
timer.stop();
timeline.stop();
}
private KeyFrame getFrame() {
Duration duration = Duration.millis(60/speedOfRotating);

EventHandler<ActionEvent> onFinished = new EventHandler<ActionEvent>() {
    public void handle(ActionEvent t) {
    LatLong latLong = LongitudeLatitudeUtil.getLatLongByDistanceAndAngle(center, time, size);
    Point endPoint = FigureUtil.translateGeographicalToViewCoords(latLong.longitude, latLong.latitude, mapViewState);
    line.setEndX(endPoint.x);
    line.setEndY(endPoint.y);
    time++;
    }
};
KeyFrame keyFrame = new KeyFrame(duration, onFinished);
return keyFrame;
}

private void startTimer() {
timer = new AnimationTimer() {
    @Override
    public void handle(long l) {
    time++;
    if (time > 360) {
        time = 0;
    }
    }
};
timer.start();
}

public void start() {
startTimer();
timeline = new Timeline();
timeline.setCycleCount(Timeline.INDEFINITE);
timeline.setAutoReverse(true);
// You can add a specific action when each frame is started.

// timeline.getKeyFrames().remove(1);
timeline.getKeyFrames().add(getFrame());
timeline.play();

}

当我将其添加到窗格时,我遇到了这样的问题:[1]:http: //img.image-storage.com/69224197/be380fee3e074.jpg。线条在我添加到的窗格中不可见(它由虚线分隔)。

4

2 回答 2

0

您可以使用 Clipping 来掩盖节点的特定区域:

Line line = LineBuilder.create().endX( 250 ).endY( 250 ).build();
// pane to clip
FlowPane pane = FlowPaneBuilder.create().minHeight( 200 ).minWidth( 200 ).children( line ).build();
// clipping shape
Rectangle rect = RectangleBuilder.create().x(pane.getLayoutX()).y(pane.getLayoutY()).width( pane.getMinWidth() ).height( pane.getMinHeight() ).build();

pane.setClip( rect );
于 2013-08-20T11:42:48.213 回答
0

您可以简单地为您添加行的容器节点指定剪辑。

linesContainer.setClip(RectangleBuilder.create().width(linesContainer.getWidth()).height(linesContainer.getHeight()).build());

于 2013-08-20T12:36:10.220 回答