代码之家  ›  专栏  ›  技术社区  ›  Armand

为什么我的图像与另一个图像相交时不会被删除

  •  0
  • Armand  · 技术社区  · 1 年前

    我做了两个图像视图,一个是我用箭头键移动的,另一个是用过渡动画移动的。我创建了一个类,并创建了一种方法,将这两个图像和它们添加到的窗格作为参数,那么我会从窗格中删除一个图像。

    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);
                
    
            }
        }
    }
     
    

    我只是试着把代码放在主类中,但没有成功。聊天也无济于事。好吧,我希望我能在这里找到答案。

    0 回复  |  直到 1 年前