Example usage for javafx.scene.shape Circle getTranslateY

List of usage examples for javafx.scene.shape Circle getTranslateY

Introduction

In this page you can find the example usage for javafx.scene.shape Circle getTranslateY.

Prototype

public final double getTranslateY() 

Source Link

Usage

From source file:Main.java

private void addBouncyBall(final Scene scene) {
    final Circle ball = new Circle(100, 100, 20);

    final Group root = (Group) scene.getRoot();
    root.getChildren().add(ball);//from w w w.  j  a va 2 s  . c  o  m

    Timeline tl = new Timeline();
    tl.setCycleCount(Animation.INDEFINITE);
    KeyFrame moveBall = new KeyFrame(Duration.seconds(.0200), new EventHandler<ActionEvent>() {

        public void handle(ActionEvent event) {

            double xMin = ball.getBoundsInParent().getMinX();
            double yMin = ball.getBoundsInParent().getMinY();
            double xMax = ball.getBoundsInParent().getMaxX();
            double yMax = ball.getBoundsInParent().getMaxY();

            if (xMin < 0 || xMax > scene.getWidth()) {
                dx = dx * -1;
            }
            if (yMin < 0 || yMax > scene.getHeight()) {
                dy = dy * -1;
            }

            ball.setTranslateX(ball.getTranslateX() + dx);
            ball.setTranslateY(ball.getTranslateY() + dy);

        }
    });

    tl.getKeyFrames().add(moveBall);
    tl.play();
}