Java Reference
In-Depth Information
new Stop(0, Color.RED),
new Stop(1, Color.BLACK));
ball.setFill(gradient1);
final Group root = (Group) scene.getRoot();
root.getChildren().add(ball);
Timeline tl = new Timeline();
tl.setCycleCount(Animation.INDEFINITE);
KeyFrame moveBall = new
KeyFrame(Duration.seconds(.0200), (ActionEvent event) -> {
double xMin
= ball.getBoundsInParent().getMinX();
double yMin
= ball.getBoundsInParent().getMinY();
double xMax
= ball.getBoundsInParent().getMaxX();
double yMax
= ball.getBoundsInParent().getMaxY();
// Collision - boundaries
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();
}
}
Search WWH ::




Custom Search