嘿我正在尝试使用顶点作为点列表绘制多边形。在我的课堂上,我的积分榜被称为代表。我对Path不是很熟悉,但这是我用来(尝试)绘制它的代码
public void draw(Canvas canvas, Paint paint){
path.reset();
if (type != TYPE_CIRCLE) {
path.moveTo(rep.get(0).x, rep.get(0).y);
for(int i = 1; i < rep.size(); i++){
path.lineTo(rep.get(i).x, rep.get(i).y);
path.moveTo(rep.get(i).x, rep.get(i).y);
}
path.close();
canvas.drawPath(path, paint);
}
else{
canvas.drawCircle(center.x, center.y, radius, paint);
}
}
然而,没有任何东西被绘制(不在屏幕上,并且所有点都应该在屏幕尺寸内。任何想法?提前感谢。
答案 0 :(得分:0)
修正了它
public void draw(Canvas canvas, Paint paint){
path.reset();
if (type != TYPE_CIRCLE) {
path.moveTo(rep.get(0).x, rep.get(0).y);
for(int i = 1; i < rep.size(); i++){
path.lineTo(rep.get(i).x, rep.get(i).y);
}
path.lineTo(rep.get(0).x, rep.get(0).y);
path.close();
canvas.drawPath(path, paint);
}
else{
canvas.drawCircle(center.x, center.y, radius, paint);
}
}