Trying to FadeTransition an array of text nodes one at a time

I am trying to make the elements of an array Textdisappear one after another in a loop for, but for some reason they disappear together.

Here is the code:

for (int i = 0; i < citiesText.length; i++) {
    if (i != cityNum) {

        PauseTransition pause = new
        PauseTransition(Duration.millis(3000));
        FadeTransition ft = new FadeTransition(Duration.millis(3000), citiesText[i]);
        SequentialTransition st = new SequentialTransition(pause, ft);

        ft.setFromValue(1);
        ft.setToValue(0);
        st.play();
    }
}
+4
source share
2 answers

I did the same as you, but with Maps.

I got it to work by nesting SequentialTransitions.

I did something similar to this:

private SequentialTransition slideshow = new SequentialTransition();

for(int i = 0; i < citiesText.length; i++){
    SequentialTransition seq = new SequentialTransition();

    FadeTransition fade = new FadeTransition(Duration.millis(2000), citiesText[i]);
    fade.setFromValue(1);
    fade.setToValue(0);
    PauseTransition stop = new PauseTransition(Duration.millis(3000));

    seq.getChildren().addAll(fade, stop);
    slideshow.getChildren().add(seq);
}
slideshow.play();

As you can see, I invested th SequentialTransition, so that each citiesTexthas its own, but they play in order because of the externalSequentialTransition

+2
source

PauseTransition (btw Duration.seconds(3) ). , . , , Fade .

, PauseTransition, a FadeTransition, SequentionalTransition, Animation setDelay(), .

:

double delay = 0d;

for (....) {
    if (....) {
        FadeTransition fade = ....;
        ....

        fade.setDelay(Duration.seconds(delay));
        delay += 3d;
        fade.play();
    }
}
0

Source: https://habr.com/ru/post/1686667/


All Articles