clearRect in Graphics

Hello, Cocos Developers.

We’re using Graphics component in our game.
It has clear() method but doesn’t have clearRect(x, y, width, height) method that is needed.

Could you make a patch or add that method in next version?

Looking forward to hearing from you.

Any good idea please?

You can try to fill rect with a solid color or transparent color, might be helpful

Thanks for the idea.
I tried it before.

solid color (like black) - if the background layer is an image, it will show a black rect.
transparent color - It doesn’t change looking of the graphics.

Should we use mask?

I see, if it need to be blended with background, then fillRect is not sufficient. You can indeed use Mask as a parent Node of graphics, and draw stencils to cutout content inside, it’s a quite convenient approach.

It works. Thank you very much!
I hope cocos team add clearRect() to Graphics in the next version.

Is there a way to add opacity to Graphics?

It should be ok to just modify its color

No, I’ve to change opacity. not color.