Function implementation:
1. image loading ImageLoader implementation:
1) Use a blocking queue to store images: BlockingQueue images = new ArrayBlockingQueue <> (2 );
2) The Image queue ends with the Image eof: Image eof = new WritableImage (1, 1 );
3) read the specified image cyclically. Because the queue is blocked, the thread will automatically block when the queue is full.
Copy codeThe Code is as follows: public void run (){
Int id = 0;
Try {
While (true ){
String path = resources [id];
InputStream is = getClass (). getResourceAsStream (path );
If (is! = Null ){
Image image = new Image (is, width, height, true, true );
If (! Image. isError ()){
Images. put (image );
}
}
Id ++;
If (id> = resources. length ){
Id = 0;
}
}
} Catch (Exception e ){
} Finally {
If (! Canceled ){
Try {
Images. put (eof );
} Catch (InterruptedException e ){
}
}
}
}
2. The special effect is implemented using an arc switching image as an example. First, define the special effect of LengthTransition change: Set the change time, and the relationship between the number of radians and time.
Copy codeThe Code is as follows: class LengthTransition extends Transition {
Arc arc;
Public LengthTransition (Duration d, Arc arc ){
This. arc = arc;
SetCycleDuration (d );
}
@ Override
Protected void interpolate (double d ){
Arc. setLength (d * 360 );
}
}
Then set the image stack effect:
Copy codeThe Code is as follows: group. setBlendMode (BlendMode. SRC_OVER );
Next. setBlendMode (BlendMode. SRC_ATOP );
And the fade-out effect of the previous image:
FadeTransition ft = new FadeTransition (Duration. seconds (0.2), mask2 );
Finally, execute these two effects at the same time:
ParallelTransition pt = new ParallelTransition (lt, ft );
: