Implementation steps: 1, define the Flipview object. Contains the following properties:
Copy Code code as follows:
Front view
Public Node Frontnode;
Negative view
Public Node Backnode;
Whether to flip
Boolean flipped = false;
Flip Angle
Doubleproperty time = new Simpledoubleproperty (MATH.PI/2);
Positive Flip Effect
Perspectivetransform fronteffect = new Perspectivetransform ();
Reverse Flip effect
Perspectivetransform backeffect = new Perspectivetransform ();
The Create method returns what needs to be displayed:
Copy Code code as follows:
private void Create () {
Time.addlistener (New ChangeListener () {
@Override
public void changed (OBSERVABLEVALUE<? extends Number> arg0,
Number arg1, number arg2) {
SETPT (Fronteffect, Time.get ());
SETPT (Backeffect, Time.get ());
}
});
Anim.getkeyframes (). AddAll (Frame1, frame2);
Backnode.visibleproperty (). Bind (
Bindings.when (Time.lessthan (0)). Then (true). otherwise (false);
Frontnode.visibleproperty (). Bind (
Bindings.when (Time.lessthan (0)). Then (false). otherwise (true);
SETPT (Fronteffect, Time.get ());
SETPT (Backeffect, Time.get ());
Frontnode.seteffect (Fronteffect);
Backnode.seteffect (Backeffect);
GetChildren (). AddAll (Backnode, Frontnode);
}
The above code needs to be noted: As the time value changes, the values of Fronteffect and Backeffect will change as well. 2, the implementation of the Perspectivetransform effect using the Math.sin () and Math.Cos () method to simulate the 3D angle transform. Specifically implemented as follows:
Copy Code code as follows:
private void Setpt (Perspectivetransform pt, double t) {
Double width = 200;
Double height = 200;
Double radius = WIDTH/2;
Double back = HEIGHT/10;
Pt.setulx (Radius-math.sin (t) * radius);
Pt.setuly (0-math.cos (t) * back);
Pt.seturx (radius + math.sin (t) * radius);
Pt.setury (0 + math.cos (t) * back);
Pt.setlrx (radius + math.sin (t) * radius);
Pt.setlry (Height-math.cos (t) * back);
PT.SETLLX (Radius-math.sin (t) * radius);
pt.setlly (height + math.cos (t) * back);
}
3, the angle transformation in 1 seconds time from 3.14/2 to -3.14/2.
Copy Code code as follows:
Keyframe frame1 = new Keyframe (Duration.zero, New KeyValue (Time,
MATH.PI/2, interpolator.linear));
Keyframe frame2 = new Keyframe (duration.seconds (1),
New EventHandler () {
@Override
public void handle (ActionEvent event) {
flipped =!flipped;
}
}, new KeyValue (Time,-MATH.PI/2, interpolator.linear));
4, Flipview object creation: Through the constructor can be very convenient to create Flipview objects.
Copy Code code as follows:
ImageView image1 = new ImageView (New Image (GetClass ()
. getResourceAsStream ("Lion1.png"));
ImageView image2 = new ImageView (New Image (GetClass ()
. getResourceAsStream ("Lion2.png"));
Flipview flip = new Flipview (Image1, image2);
5, the effect chart: