core/component/softshade
부드러운 그늘.
Soft shade.
SoftShadeextends Component
부드러운 그늘.
- 글 뒤를 어둡게 눌러 밝은 바탕 위에서도 읽히게 할 때 쓴다. 모양을 작은 캔버스 한 장에 구워 노드의 내용 크기로 늘려 그린다.
- 부드러운 그라데이션이라 낮은 해상도로 구워 늘려도 자국이 보이지 않는다. (구운 한 픽셀이 굽기 단위만큼을 덮고, 가로세로 상한이 있다)
- 노드 크기, 모양, 색, 짙기, 양옆 흐림이 바뀌면 다시 굽는다. 노드의 불투명도는 한 장째로 먹는다.
Soft shade.
- Used to darken the area behind text so it stays readable even on a bright background. Bakes the shape into one small canvas and draws it stretched to the node's content size.
- Since it is a soft gradient, no artifacts show even when baked at low resolution and stretched. (one baked pixel covers one bake unit, and there is a width/height cap)
- Rebakes when the node size, shape, color, intensity or side blur changes. The node's opacity applies to it as a single sheet.
import { Engine, EngineConfiguration, Scene, Vector2, WorldNode, Paint, SoftShade, SoftShadeShape, Text } from "./build/vanilla.js";
class MainScene extends Scene {
async load(engine) {
await super.load(engine);
const root = this.getRoot();
const backgroundNode = new WorldNode();
backgroundNode.setContentSize(Vector2.create(640, 360));
backgroundNode.setLocalPosition(Vector2.create(320, 180));
const backgroundPaint = backgroundNode.addComponent(Paint);
backgroundPaint.setColor("#f0e6c8");
root.addChild(backgroundNode);
const shadeNode = new WorldNode();
shadeNode.setContentSize(Vector2.create(520, 90));
shadeNode.setLocalPosition(Vector2.create(320, 180));
const softShade = shadeNode.addComponent(SoftShade);
softShade.setShade(SoftShadeShape.band, "#000000", 0.6, 80);
const text = shadeNode.addComponent(Text);
text.setFontSize(36);
text.setText("Stage Clear");
root.addChild(shadeNode);
}
}
const engineConfiguration = new EngineConfiguration();
engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());내용 영역 안에서만 그리는지 반환. (구운 그늘을 내용 크기로 늘려 그린다)
- draw 를 덮어쓴 하위 클래스는 어디에 그리는지 모르므로 false.
Returns whether it draws only inside the content area. (draws the baked shade stretched to the content size)
- false for subclasses that override draw, since where they draw is unknown.
반환Returnsboolean 내용 영역 안에서만 그리면 참.True if drawing only inside the content area.
노드에서 떨어짐. (나눠 쓰던 구운 그림을 놓는다)
Detached from a node. (releases the shared baked image)
- nodeComponentNode
- 떨어지는 노드.The node being detached.
굽기. (픽셀마다 알파를 셈한다, 텍스처 캐시가 캔버스마다 한 번 올리므로 구울 때마다 새 캔버스)
Bake. (computes alpha per pixel; a new canvas on every bake, since the texture cache uploads once per canvas)
- bakeWidthnumber
- 구울 캔버스 너비. (픽셀)Width of the canvas to bake. (pixels)
- bakeHeightnumber
- 구울 캔버스 높이. (픽셀)Height of the canvas to bake. (pixels)
- fadeRationumber
- 양옆이 엷어지는 너비의 내용 너비에 대한 비. (0 ~ 0.5, 0 이면 엷어지지 않는다, band 모양만 쓴다)Ratio of the side fade width to the content width. (0 ~ 0.5, no fade if 0, used only by the band shape)
짝Counterpart: vanilla-engine SoftShade.bake_shade
그늘 설정. (모양, 색, 가장 짙은 곳의 불투명도, 띠의 양옆이 엷어지는 너비)
Sets the shade. (shape, color, opacity at the darkest point, width over which the band's sides fade)
- shapestring
- SoftShadeShape
- colorColor | string
- 그늘 색. (Color 나 "#rrggbb" 같은 색 글, 알파는 읽지 않는다)Shade colour. (a Color or a colour string such as "#rrggbb", the alpha is not read)
- opacitynumber
- 가장 짙은 곳의 불투명도. (0 ~ 1, 0 이하면 그리지 않는다)Opacity at the darkest spot. (0 ~ 1, not drawn if 0 or less)
- fadeWidthnumber
- 띠의 양옆이 엷어지는 너비. (내용 크기 단위, 내용 너비의 반까지, 0 이면 엷어지지 않는다)Width over which the band's sides fade. (content size units, up to half the content width, no fade if 0)
짝Counterpart: vanilla-engine SoftShade.set_shade
굽기 해상도 설정. (구운 한 픽셀이 덮는 단위, 가로세로 상한)
Sets the bake resolution. (unit covered by one baked pixel, width/height cap)
- bakeUnitnumber
- 구운 한 픽셀이 덮는 내용 크기 단위. (1 보다 작으면 1, 처음은 4)Content size units covered by one baked pixel. (1 if less than 1, initially 4)
- bakeMaximumSizenumber
- 구운 캔버스의 가로세로 상한. (픽셀, 2 보다 작으면 2, 처음은 256)Upper limit of the baked canvas width and height. (pixels, 2 if less than 2, initially 256)
짝Counterpart: vanilla-engine SoftShade.set_bake_resolution
모양 반환.
Returns the shape.
반환Returnsstring 모양. (SoftShadeShape)Shape. (SoftShadeShape)
짝Counterpart: vanilla-engine SoftShade.get_shape
색 반환.
Returns the color.
반환ReturnsColor 색. (setShade 에 준 색, 알파는 굽기에 쓰지 않는다)Colour. (the colour given to setShade, the alpha is not used for baking)
짝Counterpart: vanilla-engine SoftShade.get_color
가장 짙은 곳의 불투명도 반환.
Returns the opacity at the darkest point.
반환Returnsnumber 가장 짙은 곳의 불투명도.Opacity at the darkest spot.
짝Counterpart: vanilla-engine SoftShade.get_opacity
띠의 양옆이 엷어지는 너비 반환.
Returns the width over which the band's sides fade.
반환Returnsnumber 띠의 양옆이 엷어지는 너비. (내용 크기 단위)Width over which the band's sides fade. (content size units)
짝Counterpart: vanilla-engine SoftShade.get_fade_width
구운 한 픽셀이 덮는 단위 반환.
Returns the unit covered by one baked pixel.
반환Returnsnumber 구운 한 픽셀이 덮는 내용 크기 단위.Content size units covered by one baked pixel.
짝Counterpart: vanilla-engine SoftShade.get_bake_unit
구운 캔버스의 가로세로 상한 반환.
Returns the width/height cap of the baked canvas.
반환Returnsnumber 구운 캔버스의 가로세로 상한. (픽셀)Upper limit of the baked canvas width and height. (pixels)
짝Counterpart: vanilla-engine SoftShade.get_bake_maximum_size
구운 캔버스 반환. (아직 굽지 않았으면 null)
Returns the baked canvas. (null if not baked yet)
반환ReturnsHTMLCanvasElement | null 구운 캔버스. (아직 굽지 않았으면 null)The baked canvas. (null if not baked yet)
SoftShadeShapeenum
부드러운 그늘의 모양.
Shape of the soft shade.
| 이름Name | 값Value | 설명Description |
|---|---|---|
band | band | 가운데 가로줄이 가장 짙고 위아래 끝으로 차츰 엷어지는 띠. (양옆은 fadeWidth 안쪽까지 차츰)Band darkest at the horizontal center line, gradually fading toward the top and bottom edges. (the sides fade gradually up to fadeWidth inward) |
bottom | bottom | 아래 끝이 가장 짙고 위 끝에서 0 인 세로 그라데이션.Vertical gradient darkest at the bottom edge and 0 at the top edge. |