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

主宰稳场 提交于 2019-12-23 14:51:09

问题


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?


回答1:


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)



来源:https://stackoverflow.com/questions/4984308/how-fill-an-android-path-that-contain-holes-without-filling-the-holes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!