Java Reference
In-Depth Information
Understanding SubScenes
In the LightExample in the last section, we used a JavaFX 3D graphics API that we have not covered yet, the
SubScene
class. It belongs to the
javafx.scene
package. A
SubScene
is a container
Node
that can add contents to a bigger scene,
yet it can have its own camera, depth buffer, and anti-aliasing policy and can render its own content separately from
the rest of the scene.
The
SubScene
class has the following constructors:
SubScene(Parent parent, double width, double height)
•
SubScene(Parent parent, double width, double height, boolean depthBuffer,
SceneAntialiasing antiAliasing)
The three-parameter constructor creates a
SubScene
with the specified
parent
,
width
, and
height
, but without its
own depth buffer and with
SceneAntiAliasing.DISABLED
anti-aliasing level. The five-parameter constructor further
allows you to specify the depth buffer and the anti-aliasing level. It has the following public methods:
•
SceneAntialiasing getAntiAliasing()
•
boolean isDepthBuffer()
•
void setRoot(Parent)
•
Parent getRoot()
•
ObjectProperty<Parent> rootProperty()
•
void setCamera(Camera)
•
Camera getCamera()
•
ObjectProperty<Camera> cameraProperty()
•
void setWidth(double)
•
double getWidth()
•
DoubleProperty widthProperty()
•
void setHeight(double)
•
double getHeight()
•
DoubleProperty heightProperty()
•
void setFill(paint.Paint)
•
paint.Paint getFill()
•
ObjectProperty< Paint> fillProperty()
The
getAntiAliasing()
and the
isDepthBuffer()
methods return the anti-aliasing level and the depth buffer
parameters passed into the constructor. The other methods define five read-write properties for the
SubScene
class.
These are the
root
,
camera
,
width
,
height
, and
fill
properties. They behave the same way as the like-named
properties of the
Scene
class.
The major use of
SubScene
is to separate 2D and 3D contents in a JavaFX program where both are needed. That is
how we used it in the LightExample. We placed the 3D portion of our program into a
SubScene
to separate it from the
rest of the program, which consists of JavaFX controls.
•
Search WWH ::
Custom Search