高效的javafx fadetransition [英] efficient javafx fadetransition

查看:70
本文介绍了高效的javafx fadetransition的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多节点,目前正在使用下面的淡入淡出过渡代码,

I have a large amount of nodes and currently using fade trasition code below,

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,并被告知我可以使用以下内容,但是这行不通,任何人都可以帮助解决此问题

however this is CPU consuming and was told that I can use the following, however this does not work, anyone can help with this

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

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

推荐答案

您还需要设置 cycleDuration (并且我假设您正在某个地方调用 play()...):

You also need to set the cycleDuration (and I assume you are calling play() somewhere...):

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

如果仍不能解决问题,请发布 MCVE

If that doesn't fix it, please post an MCVE

这篇关于高效的javafx fadetransition的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆