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

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

마스크 컴포넌트.

## Mask extends Component

마스크 컴포넌트.
- 부착된 노드의 contentSize 영역으로 자식 노드들의 그리기를 클리핑한다.
- 실제 begin/end 호출은 노드의 draw 가 자식 그리기 직전/직후에 한다.
  (draw() 자체는 컴포넌트 출력 단계에서 호출되지만 아무것도 하지 않는다.)

예제: 둥근 창 안으로 자식 자르기

```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): 생성.
- `beginClip(graphic)` (method, since 0.2.1): 클리핑 시작. (노드의 draw 가 자식 그리기 직전에 호출)
  - `graphic` Graphic: 그래픽.
- `endClip(graphic)` (method, since 0.2.1): 클리핑 종료. (노드의 draw 가 자식 그리기 직후에 호출)
  - `graphic` Graphic: 그래픽.
- `isDrawnInsideContent()` (method, since 0.4.0): 내용 영역 안에서만 그리는지 반환. (컴포넌트 출력 단계에서는 아무것도 그리지 않는다)
  - 걸러져도 자식을 자르는 클립은 노드의 draw 가 그대로 건다.
  - draw 를 덮어쓴 하위 클래스는 어디에 그리는지 모르므로 false.
  - returns boolean: 내용 영역 안에서만 그리면 참.
- `setRoundSize(roundSize)` (method, since 0.3.0): 둥근 모서리 반지름 설정. (Paint 의 roundSize 와 같은 값을 주면 배경 모양대로 잘린다)
  - `roundSize` number: 둥근 모서리 반지름. (내용 크기 단위, 음수는 0, 0 이면 사각형)
- `getRoundSize()` (method, since 0.3.0): 둥근 모서리 반지름 반환.
  - returns number: 둥근 모서리 반지름.
