vanilladocs
vanillapunch.com
API / core/component/mask

core/component/mask

마스크 컴포넌트.

Mask component.

Maskextends Component

짝Counterpart: vanilla-engine Mask

마스크 컴포넌트.

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

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
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());
생성자constructorconstructor()#0.2.1 부터since 0.2.1소스source

생성.

Constructor.

짝Counterpart: vanilla-engine Mask.new

메서드methodbeginClip(graphic)#0.2.1 부터since 0.2.1소스source

클리핑 시작. (노드의 draw 가 자식 그리기 직전에 호출)

Starts clipping. (called by the node's draw right before drawing children)

graphicGraphic
그래픽.Graphics.

짝Counterpart: vanilla-engine Mask.begin_clip

메서드methodendClip(graphic)#0.2.1 부터since 0.2.1소스source

클리핑 종료. (노드의 draw 가 자식 그리기 직후에 호출)

Ends clipping. (called by the node's draw right after drawing children)

graphicGraphic
그래픽.Graphics.

짝Counterpart: vanilla-engine Mask.end_clip

메서드methodisDrawnInsideContent()#0.4.0 부터since 0.4.0소스source

내용 영역 안에서만 그리는지 반환. (컴포넌트 출력 단계에서는 아무것도 그리지 않는다)

  • 걸러져도 자식을 자르는 클립은 노드의 draw 가 그대로 건다.
  • draw 를 덮어쓴 하위 클래스는 어디에 그리는지 모르므로 false.

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.

반환Returnsboolean 내용 영역 안에서만 그리면 참.True if drawing only inside the content area.

메서드methodsetRoundSize(roundSize)#0.3.0 부터since 0.3.0소스source

둥근 모서리 반지름 설정. (Paint 의 roundSize 와 같은 값을 주면 배경 모양대로 잘린다)

Sets the rounded corner radius. (giving the same value as Paint's roundSize clips along the background shape)

roundSizenumber
둥근 모서리 반지름. (내용 크기 단위, 음수는 0, 0 이면 사각형)Rounded corner radius. (content size units, negative becomes 0, a rectangle if 0)

짝Counterpart: vanilla-engine Mask.set_round_size

메서드methodgetRoundSize()#0.3.0 부터since 0.3.0소스source

둥근 모서리 반지름 반환.

Returns the rounded corner radius.

반환Returnsnumber 둥근 모서리 반지름.Rounded corner radius.

짝Counterpart: vanilla-engine Mask.get_round_size