# core/component/mask (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/core/component/mask/

Mask component.

## Mask extends Component

Mask component.
- Clips the drawing of child nodes to the contentSize area of the attached node.
- The actual begin/end calls are made by the node's draw right before/after drawing children.
  (draw() itself is called in the component draw phase but does nothing.)

Example: Clip children to a rounded window

```js
import { Engine, EngineConfiguration, Scene, Vector2, WorldNode, Paint, Mask } from "./build/vanilla.js";

class MainScene extends Scene {
	async load(engine) {
		await super.load(engine);
		const windowNode = new WorldNode();
		windowNode.setContentSize(Vector2.create(200, 200));
		windowNode.setLocalPosition(Vector2.create(320, 180));
		const paint = windowNode.addComponent(Paint);
		paint.setColor("#223344");
		paint.setRoundSize(24);
		const mask = windowNode.addComponent(Mask);
		mask.setRoundSize(24);
		const root = this.getRoot();
		root.addChild(windowNode);

		const childNode = new WorldNode();
		childNode.setContentSize(Vector2.create(160, 160));
		childNode.setLocalPosition(Vector2.create(160, 160));
		const childPaint = childNode.addComponent(Paint);
		childPaint.setColor("#ff6633");
		windowNode.addChild(childNode);
	}
}

const engineConfiguration = new EngineConfiguration();
engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());
```

- `constructor()` (constructor, since 0.2.1): Constructor.
- `beginClip(graphic)` (method, since 0.2.1): Starts clipping. (called by the node's draw right before drawing children)
  - `graphic` Graphic: Graphics.
- `endClip(graphic)` (method, since 0.2.1): Ends clipping. (called by the node's draw right after drawing children)
  - `graphic` Graphic: Graphics.
- `isDrawnInsideContent()` (method, since 0.4.0): Returns whether it draws only inside the content area. (draws nothing in the component draw phase)
  - Even if culled, the node's draw still applies the clip that cuts children.
  - false for subclasses that override draw, since where they draw is unknown.
  - returns boolean: True if drawing only inside the content area.
- `setRoundSize(roundSize)` (method, since 0.3.0): Sets the rounded corner radius. (giving the same value as Paint's roundSize clips along the background shape)
  - `roundSize` number: Rounded corner radius. (content size units, negative becomes 0, a rectangle if 0)
- `getRoundSize()` (method, since 0.3.0): Returns the rounded corner radius.
  - returns number: Rounded corner radius.
