Animation‎ > ‎

Animate Position


The JavaFX Transition API lets you quickly create animation sequences based on object properties.  The following shows how to animate an object's pisition using the TranslateTransition class.  The following code updates the object's translateX and translateY properties:

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

TranslateTransition {
    node: circle
    duration: 3s
    toX:w toY:h
    repeatCount: FadeTransition.INDEFINITE autoReverse: true
}.playFromStart();

See Animation
When the code execute, you will see the circle being moved from one corner to another.  
Click here to see animation.



AThe 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!