Java Reference
In-Depth Information
The
Glow
and
Bloom
effects are comparable in function and usage. In this sec-
tion, we'll supply examples of both, ultimately contrasting the subtle differences
that
Glow
and
Bloom
provide for the JavaFX developer.
Glow
To show the
Glow
effect, we'll borrow an idea from our sample Sudoku applica-
tion. While playing the Sudoku game, when you click on a space on the board,
the number inside that space will glow for the duration of the mouse click. So
applying a
Glow
effect to one of the numbers, which are represented as images, is
as easy as this:
ImageView {
effect: Glow { level: .9 }
image: Image {
url: "{__DIR__}8-bold.png"
}
}
The
level
instance variable that is part of
Glow
is responsible for setting the
intensity of the glow effect. It takes a number ranging in value from 0 to 1. Fig-
ure 6.24 shows what the number image looks like under normal conditions and
how it appears when a
Glow
effect with intensity level .9 is applied.
Figure 6.24
Before and After a Glow Effect Has Been Applied
To provide slightly more context within the Sudoku application, the
Glow
effect
is achieved by catching and handling the mouse events that occur on the node
represented by the board space. When the mouse is pressed on a space, a
Glow
effect is assigned to the image occupying that space. When the mouse is
released, the effect is taken away. The
onMousePressed
and
onMouseReleased
handlers of the Sudoku
SpaceNode
look as follows:
override var onMousePressed = function(me : MouseEvent)
: Void {
me.node.effect = Glow { level: 0.9 };
}
Search WWH ::
Custom Search