所以我正在尝试创建一个雪人并为其左右手臂设置动画,我查看了Oracle文档,并尝试尽可能地将时间写入示例设置的方式。
作为参考,这是我正在看的代码示例:
final Rectangle rectBasicTimeline = new Rectangle(100, 50, 100, 50);
rectBasicTimeline.setFill(Color.RED);
...
final Timeline timeline = new Timeline();
timeline.setCycleCount(Timeline.INDEFINITE);
timeline.setAutoReverse(true);
final KeyValue kv = new KeyValue(rectBasicTimeline.xProperty(), 300);
final KeyFrame kf = new KeyFrame(Duration.millis(500), kv);
timeline.getKeyFrames().add(kf);
timeline.play();
现在,这是我创建左臂的代码,并且(如果有效)动画它。我的缺陷在哪里?我该如何解决?
private void drawLeftArm(GraphicsContext gc)
{
leftArm = new Ellipse();
leftArm.setCenterX(90.0);
leftArm.setCenterY(160.0);
leftArm.setRadiusX(100.0);
leftArm.setRadiusY(30.0);
gc.setFill(Color.AQUAMARINE);
gc.fillOval(leftArm.getCenterX(), leftArm.getCenterY(), leftArm.getRadiusX(), leftArm.getRadiusY());
timeLine = new Timeline();
timeLine.setCycleCount(Timeline.INDEFINITE);
timeLine.setAutoReverse(true);
KeyValue LeftValue = new KeyValue(leftArm.centerYProperty(), 100);
KeyFrame keyFrame = new KeyFrame(Duration.millis(1000), LeftValue);
timeLine.getKeyFrames().addAll(keyFrame);
timeLine.play();
}