user1460631
user1460631

Reputation: 29

How do I paint a path? I'm getting a small bug

Image:

Click to see image

I was able to get the other shapes to be painted correctly this same way but for some reason, when I put the second corner of the last shape lower than the shape's forth corner, this bug occurs (the weird rectangle with a weird color).

The coordinates are all fine, but here you go. (w = screen max width, h = screen max height)

paint.setARGB(50, 0, 0, 0);
paint.setStyle(Paint.Style.FILL);
paint.setAntiAlias(true);
path.setFillType(Path.FillType.EVEN_ODD);
path.moveTo(w, h/10);
path.lineTo(w, 5*h/16);
path.lineTo(0, 2*h/5);
path.lineTo(0, h/4);
path.lineTo(w, h/10);

...

canvas.drawPath(path, paint);

Maybe it's about the Path.FillType?

Thanks in advance.

Upvotes: 0

Views: 88

Answers (1)

user1460631
user1460631

Reputation: 29

Got it!

Apparently it's about the number of corners. It should be an odd number. I just added a random new point like this:

paint.setARGB(50, 0, 0, 0);
paint.setStyle(Paint.Style.FILL);
paint.setAntiAlias(true);
path.setFillType(Path.FillType.EVEN_ODD);
path.moveTo(w, h/10);
path.lineTo(w, 5*h/16);
path.lineTo(0, 2*h/5);

path.lineTo(0, 3*h/5);

path.lineTo(0, h/4);
path.lineTo(w, h/10);

Works perfect now!

Upvotes: 1

Related Questions