Animation‎ > ‎

Animate Opacity


The JavaFX Transition API lets you quickly create animation sequences based on object properties.  The following code shows how to animate an object's opacity property using the FadeTransition: 

def w = 400;
def h = 200;
def r = 50;
def circle = Circle {
            centerX: w / 2;
            centerY: h / 2;
            radius: r
            fill: Color.BLUE;
            stroke: Color.WHITE;
            strokeWidth: 3
        }

FadeTransition {
    node: circle
    duration: 3s
    fromValue: 1.0 toValue: 0.25
    repeatCount: FadeTransition.INDEFINITE autoReverse: true
}.playFromStart();

See Animation
When the code execute, you will see the circles rotate about the center of their junction.  
Click here to see animation.

The materials on this website represent a small sample of content loosely based on the book JavaFX Application Development Cookbook.  The book offers far more content with over 80 recipes covering a range of topics from basics to advanced concepts.  

Buy the Book

You can get your copy of the book directly from the publisher. Click here to order!