I made 2 imageviews, one which I move using arrow keys and one that moves using transition animation.I created a class and created a method that takes as parameters those 2 images and the pane which they are added in.I made 2 bound that get the images boundInParent and also a boolean variable which has as value boun1 intersecting bound2.I made an if statement that if the boolean variable is true, then I would remove one image from the pane.
import javafx.geometry.Bounds;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
public class Score {
public static void scoreUpdate(ImageView spaceship, ImageView coin, AnchorPane gamePane){
Bounds bound1=spaceship.getBoundsInParent();
Bounds bound2= coin.getBoundsInParent();
boolean intersecting= bound1.intersects(bound2);
if(intersecting){
gamePane.getChildren().remove(coin);
}
}
}
I just tried putting the code in the main class, but that didn't work. Chatgpt doesn't help either. Well, I hope I find an answer here.