Roman Panaget
Roman Panaget

Reputation: 2448

Android Canvas rendering

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

Answers (1)

curob
curob

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

Related Questions