Java Reference
In-Depth Information
Lighting
The shadowing effects mentioned in the previous section represent one of many
options available that can be used to give ordinary two-dimensional objects a
three-dimensional look and feel. Another technique found in the JavaFX toolbox
is lighting . The Lighting effect introduces a configurable light source that can
be shone onto your content to produce a sense of depth. To use lighting, you
must assign your content's effect variable with an instance of the javafx
.scene.effect.Lighting class. Let's elaborate by offering up a straightfor-
ward example. The code snippet that follows shows how a Lighting effect can
be added to a Rectangle.
Rectangle {
width: 150,
height: 100
fill: Color.WHITE
effect: Lighting {
light: PointLight {
x: 0, y: 200, z: 35
}
}
}
To be of any real use, the Lighting object literal needs to, at minimum, define
its light instance variable. Derived from the base javafx.scene.effect
.light.Light class, JavaFX provides three lighting effects, out of the box, for
this purpose. Table 6.2 describes these lighting effects.
Like many of its relatives, the lighting effects come along with a good deal of
configurable parameters. Instead of regurgitating verbatim what is already in the
Ta b l e 6 . 2
Lighting Effects
Lighting Effect
Description
DistantLight
Represents a distant light source by defining an azimuth and elevation in
degrees relative to the content.
PointLight
Demonstrated above, defines a light source in 3D space with x , y , and z
coordinates.
SpotLight
A subclass of PointLight , in addition to defining a light source in 3D
space, SpotLight allows for configuration of the light source's direc-
tion and focus.
 
Search WWH ::




Custom Search