如何更改keyvalue';在javafx时间线中,目标值是多少?
在动画运行时,有任何方法可以连续更改keyvalues的目标值,而不是将固定值作为目标 为了实现这一目标,我将目标值与一个不断变化的节点的宽度属性绑定在一起。但是当动画开始时,绑定根本不起作用。目标值没有更新和卡住 这是动画的代码如何更改keyvalue';在javafx时间线中,目标值是多少?,java,animation,javafx,bind,Java,Animation,Javafx,Bind,在动画运行时,有任何方法可以连续更改keyvalues的目标值,而不是将固定值作为目标 为了实现这一目标,我将目标值与一个不断变化的节点的宽度属性绑定在一起。但是当动画开始时,绑定根本不起作用。目标值没有更新和卡住 这是动画的代码 public void setGlowAnimation(){ System.out.println("WIDTH "+width.getValue()); KeyValue value = new KeyValue(glowshape.centerX
public void setGlowAnimation(){
System.out.println("WIDTH "+width.getValue());
KeyValue value = new KeyValue(glowshape.centerXProperty(),width.getValue(),Interpolator.EASE_OUT);
KeyFrame keyframe1 = new KeyFrame(Duration.millis(2000),value);
glow_timeline = new Timeline();
glow_timeline.setCycleCount(Timeline.INDEFINITE);
glow_timeline.setAutoReverse(true);
glow_timeline.getKeyFrames().add(keyframe1);
}
public void init(){
indetermination();
setStartAnimation();
createEllipse();
width = new SimpleDoubleProperty();
width.bind(this.widthProperty());
setGlowAnimation();
}
我认为当时间线像那样处于活动状态时,您不能修改它。考虑使用<代码>转换< /代码>代替:
import javafx.animation.Animation;
import javafx.animation.Interpolator;
import javafx.animation.Transition;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
import javafx.util.Duration;
public class AdaptiveAnimation extends Application {
@Override
public void start(Stage primaryStage) {
Circle circle = new Circle(0, 100, 25, Color.CORNFLOWERBLUE);
Pane pane = new Pane(circle);
Interpolator interp = Interpolator.EASE_BOTH ;
Transition transition = new Transition() {
{
setCycleDuration(Duration.millis(2000));
}
@Override
protected void interpolate(double frac) {
double x = interp.interpolate(0, pane.getWidth(), frac);
circle.setCenterX(x);
}
};
transition.setCycleCount(Animation.INDEFINITE);
transition.setAutoReverse(true);
Scene scene = new Scene(pane, 600, 600);
primaryStage.setScene(scene);
primaryStage.show();
transition.play();
}
public static void main(String[] args) {
launch(args);
}
}
在调整窗口大小时,这有点令人不安,但它提供了基本的想法。我认为当时间线处于活动状态时,您无法修改它。考虑使用<代码>转换< /代码>代替:
import javafx.animation.Animation;
import javafx.animation.Interpolator;
import javafx.animation.Transition;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
import javafx.util.Duration;
public class AdaptiveAnimation extends Application {
@Override
public void start(Stage primaryStage) {
Circle circle = new Circle(0, 100, 25, Color.CORNFLOWERBLUE);
Pane pane = new Pane(circle);
Interpolator interp = Interpolator.EASE_BOTH ;
Transition transition = new Transition() {
{
setCycleDuration(Duration.millis(2000));
}
@Override
protected void interpolate(double frac) {
double x = interp.interpolate(0, pane.getWidth(), frac);
circle.setCenterX(x);
}
};
transition.setCycleCount(Animation.INDEFINITE);
transition.setAutoReverse(true);
Scene scene = new Scene(pane, 600, 600);
primaryStage.setScene(scene);
primaryStage.show();
transition.play();
}
public static void main(String[] args) {
launch(args);
}
}
当您调整窗口大小时,这有点紧张,但它提供了基本的想法。您是否调用过
glow\u timeline.play()
?我在代码中的任何地方都没有看到它。是的,我确实在任务方法中调用了glow\u timeline.play(),但实际上我在这里没有包含它。您是否调用过glow\u timeline.play()
?我在你的代码中没有看到它。是的,我确实在任务方法中调用了glow_timeline.play(),但实际上我没有包括在这里。Thanx很多,我以后肯定会尝试转换。但幸运的是,我通过使用一个小技巧解决了这个问题。我所做的不是设置glow_timeline.setCycleCount(timeline.unfinite),而是将其设置为glow_timeline.setCycleCount(1),并添加了一个在动画结束后触发并执行setGlowAnimation()的处理程序方法并启动动画。现在,每次新的时间线对象生成运行1个周期的运行,然后触发一个处理程序,该处理程序使用更新的键值创建一个新的时间线对象,并播放该对象。这可能不是一个好的编码方法,但它解决了问题…Thanx很多,我以后肯定会尝试转换。但幸运的是,我通过使用一个小技巧解决了这个问题。我所做的不是设置glow_timeline.setCycleCount(timeline.unfinite),而是将其设置为glow_timeline.setCycleCount(1),并添加了一个在动画结束后触发并执行setGlowAnimation()的处理程序方法并启动动画。现在,每次新的时间线对象生成运行1个周期的运行,然后触发一个处理程序,该处理程序使用更新的键值创建一个新的时间线对象,并播放该对象。这可能不是一种好的编码方法,但它解决了问题。。。。。