Java Reference
In-Depth Information
Ultimately
MediaLoader
allows this application to load
Images
and
ImageSequences
, which are used
by
ImageSequenceViews
to animate a number of images in the scene. Let's look at
ImageSequence
found in
Listing 7-3 and see how it is implemented.
Listing 7-3.
ImageSequence
public class ImageSequence {
public-init var classpathBase:String;
public-init var imageCount:Integer;
public-init var backgroundLoading:Boolean = false;
public var images:Image[];
init{
for (i in [1..imageCount]){
var classpath = "{classpathBase}{numberToString(i)}.png";
insert MediaLoader.image(classpath, backgroundLoading) into images;
}
}
function numberToString(i:Integer):String{
if (i < 10){
return "000{i}";
} else if (i < 100){
return "00{i}";
} else if (i < 1000){
return "0{i}"
}
return "{i}"
}
public function progress():Number{
var totalProgress = 0.0;
for (i in [0..sizeof(images)]){
totalProgress += images[i].progress;
}
return totalProgress/sizeof(images);
}
}
In Listing 7-3 we see that
ImageSequence
basically holds a JavaFX sequence of
Images
called
images
plus some details about the
Images
stored in the variables
classpath
,
imageCount
, and
backgroundLoading
. In the
init
function of the class
ImageSequence
, each
Image
is loaded and inserted
into the sequence images. Note that
ImageSequence
used
MediaLoader
to load each
Image
, which ensures
that even images that might be stored in another
ImageSequence
are loaded only once.
The function
numberToString
is used to format a number by padding it with the correct number of
zeros. This is somewhat arbitrary, as Blender names the files with four digits by default. Other tools will
export images with different formatting, so it might be necessary to either rename all of the files or
change how this function works.