Example usage for javafx.scene.shape Circle setTranslateY

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

Introduction

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

Prototype

public final void setTranslateY(double value) 

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);//w  ww. java2  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();
}