Java Reference
In-Depth Information
The Fade type can be
IN
,
OUT
, or
BOTH
, and these are defined in the Java enumer-
ation
FadeType
. If the fade type is
IN
, when the node is shown, its opacity
changes from zero, or invisible, to 1.0, totally visible. Also, its scaling transitions
from a minimum to a maximum scale, with the default set to 0.0 and 1.0, respec-
tively. It the fade type is
OUT
, when the node is changing to not shown, the node's
opacity and scaling will reverse direction, with opacity changing to 0.0 and scal-
ing to the minimum. Of course, the
BOTH
type does this when the node is chang-
ing from not shown to shown and again when the node is changing from shown
to not shown. The duration of the transition is set using an instance variable,
duration
. Listing 12.5 shows the JavaFX code for these attributes in the
Fader
class.
Listing 12.5
Fader.fx
public class Fader extends CustomNode {
// holds the node that will be faded.
public var
node
:Node;
public var
type = FadeType.IN
on replace {
if(type != null)
fade();
};
public var
duration
:Duration = 2s;
public var
startScale
: Number = 0.0;
public var endScale: Number = 1.0;
To control the transitions, we added an instance variable,
show
. When
show
is set
to true, the node is made visible, and then the transition starts. When
show
changes to false, the reverse transition is started, and the node's
visible
variable
is set to false. The actual fade transitions are controlled with a
Timeline
that is
started in the function
fade()
.
This is demonstrated in Listing 12.6.
Listing 12.6
Fader.fx - show()
public var interpolator = Interpolator.LINEAR;
var scale = 0.0;
public var
show
: Boolean on replace {
if(show) {
visible = true;
fade();
}else if(visible) {
if ( type == FadeType.OUT or
Search WWH ::
Custom Search