Is there a way to clip in zimjs?

Is there a way to clip in zimjs?

I am drawing a bunch of vector arrows to represent electric field. I am adding the arrows to a container using addTo(). The container is smaller than the stage, leaving room for user controls. But I am drawing the arrows slightly beyond the size of the container, in order to completely fill the container.

Is there a way to clip what is visible in the container, using something like a rectangle or another container or such?

Thanks!

Yes - we use setMask(). The mask, when using setMask must be a shape - probably a Rectangle is good. So make a Rectangle and put it behind the Container so add it first. Then say container.setMask(rect); You will only see the arrows where the rectangle is. If you want, you can set the rect.alp(0) or make it the color of the frame F.color then you will not see the rectangle. Look up https://zimjs.com/docs.html?item=setMask for more details. Made an example too - press code to see the code.

Perfect! Thanks!

1 Like