Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javafx中的SVG路径冲突_Svg_Javafx 2_Collision Detection - Fatal编程技术网

javafx中的SVG路径冲突

javafx中的SVG路径冲突,svg,javafx-2,collision-detection,Svg,Javafx 2,Collision Detection,我今天的问题相对简单,有没有一种方法可以通过SVGPath的Javafx实现进行冲突处理?如果我把一个粒子扔到屏幕上,它遇到svgPath的任何部分,它将发出碰撞信号 我尝试使用常规边界碰撞,但如果路径的形状像“L”,它会为SVGPath提供一个巨大的边界框 我所特别使用的路径是: m 252,12.362183 c 1.03171,23.632637 -4.57241,55.427587 9,69 65.41611,65.416117 361.05896,43.999997 469,

我今天的问题相对简单,有没有一种方法可以通过SVGPath的Javafx实现进行冲突处理?如果我把一个粒子扔到屏幕上,它遇到svgPath的任何部分,它将发出碰撞信号

我尝试使用常规边界碰撞,但如果路径的形状像“L”,它会为SVGPath提供一个巨大的边界框

我所特别使用的路径是:

m 252,12.362183
     c 1.03171,23.632637 -4.57241,55.427587 9,69 65.41611,65.416117 361.05896,43.999997 469,43.999997
我是否必须重新插值直线,并让数组存储一组(x,y)位置,我会不断检查这些位置?这似乎相当笨拙,但我实在想不出任何其他(更简单的)方法

我为常规有界碰撞尝试的代码如下:

observableBooleanValue colliding = Bindings.createBooleanBinding(new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                return particle.getBoundsInParent().intersects(path.getBoundsInParent());
            }

        }, particle.boundsInParentProperty(), path.boundsInParentProperty());

        System.out.println("path bounds: " + path.boundsInParentProperty());
        colliding.addListener(new ChangeListener<Boolean>() {
            @Override
            public void changed(ObservableValue<? extends Boolean> obs,
                    Boolean oldValue, Boolean newValue) {
                if (newValue) {
                    System.out.println("Colliding");
                } else {
                    System.out.println("Not colliding");
                }
            }
        });

pathloader只是简单地加载到我上面提到的路径中,尝试使用模糊和透明,没有收紧路径冲突的效果

一开始我以为它可能是重复的,但因为SVG路径都是基于贝塞尔曲线的插值线,所以我找不到任何方法围绕这种类型的javafx构造生成“一组边界”,因此,单独的问题。检查编辑以获取有关尝试使用“shape.intersect”方法在屏幕上查找视觉交点的信息。
particle.layoutYProperty().addListener(new ChangeListener<Number>(){

            @Override
            public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
               Shape intersect = Shape.intersect(path, particle);
                if ((intersect.getBoundsInLocal().getHeight() != -1) && (intersect.getBoundsInLocal().getWidth() != -1)) {
                    System.out.println("Collison!");
                }
            }

        });
/**
     * This function helps to make the path for animating particles
     *
     * @throws IOException
     */
    public void makePaths() throws IOException {
        PathLoader loader = new PathLoader();
        path = new SVGPath();
        path.setContent(loader.getPath(1));
        path.setStroke(Color.AQUA);
        //path.setFill(Color.TRANSPARENT);
        //path.setEffect(boxBlur);


    }