i'm using JavaFX to build a cardgame and i struggle to add simple animations.
I have a HBox with multiple ImageViews in them. Every Image has a right margin of -80 to get the images to overlap each other.
Now i want to animate the card when it's added. I want to place it somewhere on the screen (opponent player hand) and move it to the position it would've been without animation.
I tried this:
// Animation
Path path = new Path();
MoveTo moveTo = new MoveTo(200, 200);
moveTo.setAbsolute(true);
path.getElements().add(moveTo);
LineTo lineTo = new LineTo(0, 0);
path.getElements().add(lineTo);
PathTransition pathTransition = new PathTransition();
pathTransition.setDuration(Duration.millis(4000));
pathTransition.setPath(path);
pathTransition.setNode(imageView);
pathTransition.setCycleCount(1);
pathTransition.play();
But it doesn't work like i want it to. I have no clue how to handle the coordiantes and can't find a solution for my problem.
I hope someone can help me with m y problem
The correct
Path
geometry hinges critically on the layout of the rootParent
. In the example below, thePath
goes from the top-left to the bottom-right, adjusted to keep the movingRectangle
in view. It adds the rectangle to aPane
, "since it does not perform layout beyond resizing resizable children to their preferred sizes." If you use a more advanced layout, e.g.StackPane
, adjust the alignment accordingly: