How to fill an Android path that contains holes without filling holes?

I am currently programming a very simple game for Android (API level 7) to open and learn the SDK for Android. This game includes a form of drawing on the screen, which will change color when touched.

Some shapes may insert one or more holes. My problem: if I touch the shape, everything changes, even the holes. "Here is the pseudocode I use, the shape is the polygon I want to draw, it borders on the outer border, it breathes an array of its holes. The hole and the border contain an array of their points .

Path MyPath = Path(); Path.moveTo(boundary.points[0].x, boundary.point[0].x); for (point in boundary) { MyPath.lineTo(point.x, point.y); } Path.close(); for (hole in shape.holes) { MyPath.moveTo(hole.points[0].x,hole.points[0].y); for (point in hole) { MyPath.lineTo(point.x, point.y); } MyPath.close(); } // setting Paint here... canvas.drawPath(MyPath, MyPaint); 

Is there something I miss about Path in Android, or do you have an alternative way to do this?

+4
source share
1 answer

Are you sure you are using the correct rule for filling the path? If you use, for example, WINDING as a rule of filling, the holes should be in opposite directions relative to the outer border (for example, the border is counterclockwise and the holes are clockwise)

+7
source

Source: https://habr.com/ru/post/1339545/


All Articles