Reputation: 2448
I'm making a game and I want to partially hide the canvas of a SurfaceView like this:
From this:
To this:
Is there any way to do this with Canvas methods? Thanks in advance.
Upvotes: 0
Views: 93
Reputation: 745
Put this code in the method that draws on the canvas:
Path invertedCircle = new Path();
int radius = (canvas.getWidth() < canvas.getHeight()) ? canvas
.getWidth() / 4 : canvas.getHeight() / 2;
invertedCircle.addCircle(canvas.getWidth() / 2,
canvas.getHeight() / 2, radius, Direction.CW);
invertedCircle.setFillType(FillType.INVERSE_EVEN_ODD);
Paint p = new Paint();
p.setColor(Color.BLACK);
canvas.drawPath(invertedCircle, p);
This fills everything except a circle (at the center) with black. If you have drawn your rectangles and the white background first then this should get you close.
Upvotes: 1