Game Development Reference
In-Depth Information
Image(String url , boolean backgroundLoading )
Two Image() constructor methods also use the java.io.InputStream class, which fur-
nishes a real-time stream (like streaming video or audio, only customized for a Java ap-
plication) of input data to the Image() constructor method. These two Image object
constructor formats take the following formats (simple and complex):
Image(InputStream is ) // This is the simple format. The
complex format would thus be as follows:
Image(InputStream is, double newWidth , double newHeight ,
boolean preserveAspect , boolean smooth )
Therefore, the Image class (object) is used to prepare a digital image asset for use,
that is, to read its data from a URL; resize them, if necessary (using whatever smooth-
ing and aspect ratio lock you like); and load them asynchronously, while other things
are going on in your application. It is important to note that the Image class (or object)
does not display an image asset: the Image class just loads it; scales it, if needed; and
places it in system memory to be used in your application.
To display an Image object, you will need to use a second class (object), called an
ImageView class. The ImageView object can be used as a node on your Scene Graph
and references and then “paints” the Image object data onto the layout container, which
holds the ImageView node (in this case, a StackPane Scene Graph root and Parent node
to the leaf ImageView node). I will be covering the ImageView class in the next sec-
tion.
From a digital image-compositing perspective, the StackPane class (object) is the
image-compositing engine, or layer manager, if you will, and each ImageView object
represents an individual layer in the layer stack. An Image object contains the digital
image data in the ImageView layer or in more than one ImageView, if needed, as the
Image objects and the ImageView objects are decoupled and exist independently of
each other.
JavaFX ImageView Class: Displaying Digital Images
in a Design
The ImageView class is a public class that directly extends the javafx.scene.Node su-
perclass, which is an extension of the java.lang.Object (see Chapter 4 ) . The ImageView
Search WWH ::




Custom Search