如何填补不包含填充孔对准一个Android的路径? [英] How fill an Android Path that contain holes without filling the holes?

查看:130
本文介绍了如何填补不包含填充孔对准一个Android的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在编写针对Android非常简单的游戏(API 7级),以发现和了解了Android SDK。这场比赛涉及到触摸时会改变颜色在屏幕上绘制形状。

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.

有些形状可嵌入一个或几个洞。我的问题是:如果我触摸造型,整个事情的颜色变化,就连洞。这里是伪code我用的,外形是我要绘制多边形,边界是外边界,孔的孔阵列。孔和边界保持其点的数组。

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

时的我丢失的东西关于Android的路径或者你有一些替代办法做到这一点?

Is their something I'm missing regarding Path in Android or do you have some alternative way to do it?

推荐答案

您确定您使用了正确的路径填充规则?如果您在使用例如缠绕作为填充统治孔必须在涉及相反方向的外边界(如边界逆时针和顺时针孔)

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)

这篇关于如何填补不包含填充孔对准一个Android的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆