Java Path2D.Double,附加但没有减去

时间:2014-06-18 01:53:17

标签: java graphics2d subtraction path-2d

我已经研究过使用EVEN-ODD绕组规则来在区域中创建孔。事情就在论坛上,我能想到的是Path2D.Double()在其自身内附加一个洞。我想在已经存在的Path2D中创建一个整体,就像Area类有Area.subtract(new Shape());确实。我很绝望。我知道Path2D有能力改善游戏的性能。

Path2D.Double d = new Path2D.Double(Path2D.WIND_EVEN_ODD);// this is a much larger circle which I will be using to subtract from the tile...

d.append(current_draw_area.createTransformedArea(mouse_point), false);//Note that this is an area without a winding rule...

Path2D.Double shape= new Path2D.Double();//this is actually a empty tile which is simply a rectangle, but will eventually have something in it to subtract from...

shape.append(d, false);

注意:输出应该是一个空方块,因为更大的圆圈完全覆盖了瓷砖,或者是一个瓷砖,其中圆圈和现有瓷砖形状的交叉点的结果被移除,留下剩下的东西瓷砖......

研究链接 StackOverflow Thread

修改

for (int i = 0; i < paint_textures.size(); i++) {

            if (!current_paint.equals(paint_textures.get(i))) {

                paint_regions.get(paint_textures.get(i)).subtract(new Area(current_draw_area.createTransformedArea(mouse_point)));

                for (int y = adjY - 100; y < adjY + current_draw_area.getBounds().height + 100; y += 100) {

                    for (int x = adjX - 100; x < adjX + current_draw_area.getBounds().width + 100; x += 100) {

                        try {

                            if (paint_tiles.get(paint_textures.get(i)).get(new Point(x, y)).intersects(new Rectangle(x, y, 100, 100))) {

                                Area a = (Area) paint_regions.get(paint_textures.get(i)).clone();
                                a.intersect(new Area(new Rectangle(x, y, 100, 100)));

                                Path2D.Double d = new Path2D.Double(a.getPathIterator(null).getWindingRule());
                                d.append(a.getPathIterator(null), false);//This Causes painting to be Jumpy...

                                paint_tiles.get(paint_textures.get(i)).replace(new Point(x, y), d);

                            }

                        } catch (NullPointerException e) {
                        }

                    }

                }
            }
        }

0 个答案:

没有答案