core/component/shadowimage
그림자를 깐 그림.
Image with a shadow.
ShadowImageextends Component
그림자를 깐 그림.
- 그림(또는 아틀라스의 한 조각)을 노드 안에 비를 지켜 가장 크게, 가운데로 그린다.
- ShadowText 와 같이 그림의 모양(불투명도) 밑에 그림자를 칠한 모습을 캔버스 한 장에 구워 그 한 장을 그린다. 노드의 불투명도가 그림과 그림자에 한 장째로 먹는다.
- 그림 색을 주면 그림을 그 색 한 빛의 모양으로 칠한다. (같은 자리 위에 원래 그림을 얹어 그림자만 남기는 감쌈 등)
- 그리는 배율(기기의 DPR, 뷰 배율), 그림, 색, 그림자, 노드 크기가 바뀌면 다시 굽는다. 그림자가 번지는 만큼 가장자리를 넓힌다.
Image with a shadow.
- Draws the image (or one piece of an atlas) inside the node as large as possible while keeping its ratio, centered.
- Like ShadowText, bakes the look of the shadow painted beneath the image's shape (opacity) into one canvas and draws that single sheet. The node's opacity applies to the image and shadow as one sheet.
- If an image color is given, paints the image as a single-color shape of that color. (e.g. a wrap that places the original image on top at the same spot so only the shadow remains)
- Rebakes when the draw scale (device DPR, view scale), image, color, shadow or node size changes. Widens the edge by the shadow blur amount.
import { Engine, EngineConfiguration, Scene, Vector2, WorldNode, ShadowImage, ImageAsset } from "./build/vanilla.js";
class MainScene extends Scene {
async load(engine) {
await super.load(engine);
const imageAsset = new ImageAsset();
await imageAsset.load("assets/icons/icon.png");
const iconNode = new WorldNode();
iconNode.setContentSize(Vector2.create(128, 128));
iconNode.setLocalPosition(Vector2.create(320, 180));
const shadowImage = iconNode.addComponent(ShadowImage);
shadowImage.setImage(imageAsset.image);
shadowImage.setShadow("#000000", 0.6, 6, 8);
const root = this.getRoot();
root.addChild(iconNode);
}
}
const engineConfiguration = new EngineConfiguration();
engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());그리는 사각형을 rect 에 적기. (오버라이드: 그림은 내용 영역 안에 비를 지켜 들어가고, 그림자가 번짐과 내림만큼 넘친다)
- 내용 영역을 사방으로 번짐의 두 배와 굽는 칸의 여유만큼, 아래(내림이 음수면 위)로 그림자 내림만큼 더 넓힌다. (캔버스 shadowBlur 는 표준 편차 blur / 2 의 가우스라 꼬리가 1.5 배까지 간다, 넉넉히 두 배)
- 그림이 있는지와 상관없이 같은 사각형을 알린다. (그림을 바꿔도 다시 셈하지 않는다)
Writes the drawn rectangle to rect. (Override: the image fits inside the content area keeping its ratio, and the shadow spills by its blur and offset)
- The content area grows on all sides by twice the blur plus the bake padding, and downward (upward if negative) by the shadow offset. (Canvas shadowBlur is a Gaussian with standard deviation blur / 2 whose tail reaches 1.5 times; twice to be generous)
- Reports the same rectangle whether or not there is an image. (Changing the image does not recalculate)
- rectRect
- 그리는 사각형을 적을 곳. (노드 내용 영역의 왼쪽 위가 원점)Where to write the drawn rectangle. (origin at the top-left of the node's content area)
반환Returnsboolean 노드에 붙어 있으면 참.True if attached to a node.
import { WorldNode, ShadowImage, Rect, Vector2 } from "./build/vanilla.js";
const node = new WorldNode();
node.setContentSize(Vector2.create(64, 64));
const shadowImage = node.addComponent(ShadowImage);
shadowImage.setShadow("#000000", 0.6, 6, 8);
const drawnRect = Rect.zero();
shadowImage.calculateDrawnRect(drawnRect);
console.log(drawnRect.position.x, drawnRect.size.y);노드에서 떨어짐. (나눠 쓰던 구운 그림을 놓는다)
Detached from a node. (releases the shared baked image)
- nodeComponentNode
- 떨어지는 노드.The node being detached.
그림 안의 조각 읽기. (조각이 없으면 그림 전체)
Reads the piece within the image. (the whole image if there is no piece)
반환Returns{ left: number, top: number, width: number, height: number } 그림 안의 조각. (픽셀, 조각이 없으면 그림 전체)Piece inside the image. (pixels, the whole image if there is no piece)
굽기. (그림을 한 번 칠하면 캔버스가 그 밑에 그림자를 먼저 칠한다)
- 텍스처 캐시가 캔버스마다 한 번 올리므로 구울 때마다 새 캔버스를 만든다.
Bake. (painting the image once makes the canvas paint the shadow beneath it first)
- Creates a new canvas on every bake, since the texture cache uploads once per canvas.
- imageHTMLImageElement | HTMLCanvasElement
- 그림.Image.
- sourceRectobject
- 그림 안의 조각. ({ left, top, width, height }, 픽셀)Piece inside the image. ({ left, top, width, height }, pixels)
- imageWidthnumber
- 그릴 너비. (내용 크기 단위)Width to draw. (content size units)
- imageHeightnumber
- 그릴 높이. (내용 크기 단위)Height to draw. (content size units)
- bakeScalenumber
- 굽는 배율. (Graphic.calculateTextBakeScale)Bake scale. (Graphic.calculateTextBakeScale)
그릴 크기로 줄인 그림. (그림 색이 있으면 그 색 한 빛의 모양, 그림자 없이)
Image scaled down to the draw size. (if there is an image color, a single-color shape of that color, without the shadow)
- imageHTMLImageElement | HTMLCanvasElement
- 그림.Image.
- sourceRectobject
- 그림 안의 조각. ({ left, top, width, height }, 픽셀)Piece inside the image. ({ left, top, width, height }, pixels)
- scaledImageWidthnumber
- 줄인 너비. (픽셀)Scaled width. (pixels)
- scaledImageHeightnumber
- 줄인 높이. (픽셀)Scaled height. (pixels)
반환ReturnsHTMLCanvasElement | null 줄인 그림을 담은 새 캔버스. (2D 컨텍스트를 얻지 못하면 null)New canvas holding the scaled image. (null if the 2D context is unavailable)
그림 설정. (조각을 주지 않으면 그림 전체)
Sets the image. (the whole image if no piece is given)
- imageHTMLImageElement | HTMLCanvasElement | null
- 그림. (null 이면 그리지 않는다)Image. (nothing is drawn if null)
- imageRectRect | null
- 그림 안의 조각. (픽셀, 사본을 둔다, null 이면 그림 전체)Piece inside the image. (pixels, a copy is kept, the whole image if null)
짝Counterpart: vanilla-engine ShadowImage.set_image
그림 반환.
Returns the image.
반환ReturnsHTMLImageElement | HTMLCanvasElement | null 그림. (없으면 null)Image. (null if none)
짝Counterpart: vanilla-engine ShadowImage.get_image
그림 경로 설정. (적어 두기만 하고 그림을 읽지 않는다, UIDocument 가 그림 대신 이 경로를 적고 읽는다)
Sets the image path. (Only records it and does not load the image, UIDocument writes and reads this path instead of the image)
- imagePathstring
- 그림 경로.Image path.
짝Counterpart: vanilla-engine ShadowImage.set_image_path
그림 경로 반환. (정하지 않았으면 빈 글)
Returns the image path. (empty string if not set)
반환Returnsstring 그림 경로. (정하지 않았으면 빈 글)Image path. (empty string if not set)
짝Counterpart: vanilla-engine ShadowImage.get_image_path
그림 안의 조각 반환. (null 이면 그림 전체)
Returns the piece within the image. (the whole image if null)
반환ReturnsRect | null 그림 안의 조각. (null 이면 그림 전체)Piece inside the image. (the whole image if null)
짝Counterpart: vanilla-engine ShadowImage.get_image_rect
그림을 한 빛으로 칠할 색 설정. (null 이면 그림 그대로)
Sets the color for painting the image in a single color. (image as is if null)
- imageColorColor | string | null
- 그림을 한 빛으로 칠할 색. (Color 나 "#rrggbb" 같은 색 글, 알파가 칠의 불투명도, null 이면 그림 그대로)Colour to paint the image in one tone. (a Color or a colour string such as "#rrggbb", the alpha is the paint opacity, null keeps the image as is)
짝Counterpart: vanilla-engine ShadowImage.set_image_color
그림을 한 빛으로 칠할 색 반환.
Returns the color for painting the image in a single color.
반환ReturnsColor | null 그림을 한 빛으로 칠할 색. (null 이면 그림 그대로)Color to fill the image with a single color. (the image as is if null)
짝Counterpart: vanilla-engine ShadowImage.get_image_color
그림자 설정. (색, 불투명도, 그림 아래로 내려가는 만큼, 번지는 만큼)
Sets the shadow. (color, opacity, offset below the image, blur amount)
- shadowColorColor | string
- 그림자 색. (Color 나 "#rrggbb" 같은 색 글, 알파는 읽지 않는다)Shadow colour. (a Color or a colour string such as "#rrggbb", the alpha is not read)
- shadowOpacitynumber
- 그림자 불투명도. (0 ~ 1)Shadow opacity. (0 ~ 1)
- shadowOffsetnumber
- 그림자가 그림 아래로 내려가는 만큼. (내용 크기 단위)How far the shadow drops below the image. (content size units)
- shadowBlurnumber
- 0 이면 번지지 않는다.No blur if 0.
짝Counterpart: vanilla-engine ShadowImage.set_shadow
구운 캔버스 반환. (아직 굽지 않았으면 null)
Returns the baked canvas. (null if not baked yet)
반환ReturnsHTMLCanvasElement | null 구운 캔버스. (아직 굽지 않았으면 null)The baked canvas. (null if not baked yet)