高效的javafx fadetransition

时间:2014-08-22 12:18:44

标签: javafx fade

我有大量节点,目前正在使用淡入淡出传输代码,

ft1 = new FadeTransition(Duration.millis(500), hBox_outter_last);
                                       ft1.setFromValue(1.0);
                                        ft1.setToValue(0.3);
                                        ft1.setCycleCount(Animation.INDEFINITE);
                                        ft1.setAutoReverse(true);
                                       ft1.play();

然而这是CPU消耗,并被告知我可以使用以下,但这不起作用,任何人都可以帮助这个

DoubleProperty opacity = new SimpleDoubleProperty();
Transition opacityTransition = new Transition() {
    protected void interpolate(double frac) {
        opacity.set(frac);
    }
};

// elsewhere
hBox_outter_last.opacityProperty().bind(opacity);

1 个答案:

答案 0 :(得分:0)

您还需要设置cycleDuration(我假设您在某个地方呼叫play()):

Transition opacityTransition = new Transition() {
    {
        setCycleDuration(Duration.seconds(1));
    }
    protected void interpolate(double frac) {
        opacity.set(frac);
    }
};

如果仍无法解决问题,请发布MCVE