Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How fill an Android Path that contain holes without filling the holes?

I'm currently programming very simple game for Android (API level 7) to discover and learn the android SDK. This game involve drawing shape on the screen that will change colour when touched.

Some shapes may embed one or several holes. My issue is : if I touch the shape, the whole thing's colour change, even the holes'. Here is the pseudo code I use, shape is the polygon I want to draw, boundary it's outer boundary, holes an array of its holes. Hole and boundary hold 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 their something I'm missing regarding Path in Android or do you have some alternative way to do it?

like image 761
thomas Avatar asked Feb 25 '23 02:02

thomas


1 Answers

Are you sure you are using the correct path filling rule? If you are using for example WINDING as filling rule the holes must be in the opposite directions in respect to the outer boundary (e.g. border counter-clockwise and holes clockwise)

like image 147
6502 Avatar answered Feb 27 '23 16:02

6502