Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 16 ■ 3D Game animation Creation: UsinG the animation transition Classes


The byAngle DoubleProperty can be utilized to specify an incremental stop angle value from the
start of the RotateTransition. The fromAngle DoubleProperty can be used to specify a start angle value for
your RotateTransition. The toAngle DoubleProperty can be used to specify your stop angle value for your
RotateTransition.
The nested class, fields, and properties discussed previously are inherited from Animation and Transition.
There are three overloaded constructor methods for a RotateTransition class. One creates an
unconfigured RotateTransition, one creates a duration configured RotateTransition, and one creates a
duration and Node object configured RotateTransition. These three constructor methods look like the
following Java code:


RotateTransition()
RotateTransition(Duration duration)
RotateTransition(Duration duration, Node node)


There are 19 methods specifically for use in this class besides the methods inherited from Animation
and Transition superclasses extended by this class. The .axisProperty() method call specifies an axis of
rotation for the RotateTransition using an ObjectProperty format. The .byAngleProperty()
method specifies an incremental stop angle value, which is an offset from the start angle, for the
RotateTransition object.
The .durationProperty() method specifies the duration of the RotateTransition using an
ObjectProperty. The .fromAngleProperty() method specifies the start angle value for this
RotateTransition using a DoubleProperty. The .getAxis() method call gets the value of the axis property
using a Point3D object.
The .getByAngle() method will get the double value of the byAngle property. The .getFromAngle()
method call will get the double value of the fromAngle property. The .getToAngle() method call will get the
double value of the toAngle property. The .getNode() method call will get the Node object value of the node
property, and the .getDuration() method call will get the value of the duration property. The protected
void .interpolate(double value) method call, as you know, has to be provided by subclass implementations
of a Transition superclass. The .nodeProperty() method specifies the target ObjectProperty for the
RotateTransition.
The void .setAxis(Point3D value) method call is used to set the value of the property axis.
The void .setByAngle(double value) method call is used to set the value of the byAngle property.
The void .setDuration(Duration value) method call is used to set the value of the property duration.
The void .setFromAngle(double value) method call is used to set the value of the property fromAngle.
The void .setNode(Node value) method call is used to set the value of the property node.
The void .setToAngle(double value) method call is used to set the value of the property toAngle.
The .toAngleProperty() method specifies a stop angle value for the RotateTransition using a
DoubleProperty. Let’s implement the rotGameBoard and rotSpinner RotateTransition objects next to give
you some hands-on experience.


A RotateTransition Example: Set Up Your RotateAnimation Asset


Let’s create a createAnimationAssets() method to hold the RotateTransition, TranslateTransition, and
other Transition subclass objects using the following Java statement, shown highlighted in yellow (and wavy
red underlining) in Figure 16-1:


createAnimationAssets();

Free download pdf