【发布时间】: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 中的路径方面缺少的东西,还是你有其他方法可以做到这一点?
【问题讨论】: