我正在使用 RotateTransition 旋转图像,如果 (x,y) 最初是该图像上某个点的位置,并且该位置将随着图像旋转而不断变化。 我想在任何给定时间知道该点的位置。 如何获得点的新位置?
ImageView wheel= new ImageView();
wheel.setImage(image);
rotateTransition = new RotateTransition(Duration.seconds(10), wheel);
rotateTransition.setFromAngle(0);
rotateTransition.setToAngle(360);
rotateTransition.setInterpolator(Interpolator.LINEAR);
rotateTransition.setCycleCount(Timeline.INDEFINITE);
//我目前使用的方法似乎不准确:
rotateTransition.currentTimeProperty().addListener(
new ChangeListener<Duration>() {public void changed(ObservableValue<? extends Duration> ov, Duration t, Duration t1) {
double degree = ((360 * t.toSeconds()) / 10);
xVal.set(((120) * Math.cos(degree * (Math.PI / 180))) + 162.5);
yVal.set(((120) * Math.sin(degree * (Math.PI / 180)) + 162.5));
}
最佳答案
要获取当前的旋转角度,您应该使用 rotateProperty ImageView
的:
wheel.rotateProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable,
Number oldValue,
Number newValue) {
System.err.println("Rotation of " + newValue + " degrees");
}
});
关于java - RotateTransition 当前角度 javafx2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15226014/