// 创建共同旋转动画 RotateTransition rotateTransition1 = new RotateTransition(Duration.seconds(0), group1); RotateTransition rotateTransition2 = new RotateTransition(Duration.seconds(0), group2); if (brush.getSpeed() == 0) { rotateTransition1.setDuration(Duration.seconds(0)); rotateTransition2.setDuration(Duration.seconds(0)); } else { rotateTransition1.setDuration(Duration.seconds(6.0 / brush.getSpeed())); rotateTransition2.setDuration(Duration.seconds(6.0 / brush.getSpeed())); } rotateTransition1.setFromAngle(0); rotateTransition1.setToAngle(-100); rotateTransition1.setCycleCount(Animation.INDEFINITE); rotateTransition1.setAutoReverse(true); rotateTransition1.setInterpolator(Interpolator.LINEAR); rotateTransition2.setFromAngle(0); rotateTransition2.setToAngle(-100); rotateTransition2.setCycleCount(Animation.INDEFINITE); rotateTransition2.setAutoReverse(true); rotateTransition2.setInterpolator(Interpolator.LINEAR);如何让这段代码动一次,延迟三秒再动一次
时间: 2023-12-27 19:02:44 浏览: 215
google/protobuf/duration.proto
你可以使用 `PauseTransition` 延迟三秒,然后在 `onFinished` 中启动旋转动画。以下是修改后的代码示例:
```
RotateTransition rotateTransition1 = new RotateTransition(Duration.seconds(0), group1);
RotateTransition rotateTransition2 = new RotateTransition(Duration.seconds(0), group2);
if (brush.getSpeed() == 0) {
rotateTransition1.setDuration(Duration.seconds(0));
rotateTransition2.setDuration(Duration.seconds(0));
} else {
rotateTransition1.setDuration(Duration.seconds(6.0 / brush.getSpeed()));
rotateTransition2.setDuration(Duration.seconds(6.0 / brush.getSpeed()));
}
rotateTransition1.setFromAngle(0);
rotateTransition1.setToAngle(-100);
rotateTransition1.setCycleCount(Animation.INDEFINITE);
rotateTransition1.setAutoReverse(true);
rotateTransition1.setInterpolator(Interpolator.LINEAR);
rotateTransition2.setFromAngle(0);
rotateTransition2.setToAngle(-100);
rotateTransition2.setCycleCount(Animation.INDEFINITE);
rotateTransition2.setAutoReverse(true);
rotateTransition2.setInterpolator(Interpolator.LINEAR);
PauseTransition delay = new PauseTransition(Duration.seconds(3));
delay.setOnFinished(event -> {
rotateTransition1.play();
rotateTransition2.play();
});
delay.play();
```
这段代码会在启动后延迟三秒,然后启动旋转动画,并且每隔一段时间就会重复播放动画。
阅读全文