【问题标题】:How fill an Android Path that contain holes without filling the holes?如何填充包含孔的Android路径而不填充孔?
【发布时间】:2011-02-13 21:16:17
【问题描述】:

我目前正在为 Android(API 级别 7)编写非常简单的游戏,以发现和学习 android SDK。该游戏涉及在屏幕上绘制形状,触摸时会改变颜色。

某些形状可能嵌入一个或多个孔。我的问题是:如果我触摸形状,整个东西的颜色都会改变,甚至是洞。这是我使用的伪代码,形状是我要绘制的多边形,边界是外边界,孔是孔的数组。孔和边界包含它们的点数组。

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);

他们是我在 Android 中的路径方面缺少的东西,还是你有其他方法可以做到这一点?

【问题讨论】:

    标签: android graphics


    【解决方案1】:

    您确定您使用的是正确的路径填充规则吗?如果您使用例如WINDING 作为填充规则,则孔必须在相对于外部边界的相反方向(例如逆时针边界和顺时针孔)

    【讨论】:

    • 你提出了一些以前不知道的路径创建方面,我会研究一下。谢谢!
    • 你是对的,使用 MyPath.setFillType(Path.FillType.Even_ODD) 成功了。
    猜你喜欢
    • 1970-01-01
    • 2021-04-29
    • 1970-01-01
    • 1970-01-01
    • 2012-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多