ui/uiimageview
UI 이미지 뷰.
UI image view.
UIImageViewextends UIView
UI 이미지 뷰.
- 표시 전용. 입력을 받지 않으므로 UIView 를 상속한다.
- 노드에 부착되면 내부적으로 Sprite 컴포넌트를 자동 생성/관리한다.
- Sprite 의 이미지/색/플립/드로우모드/블렌드 등 자주 쓰는 속성을 노출한다.
UI image view.
- Display only. Inherits UIView since it takes no input.
- When attached to a node, automatically creates/manages a Sprite component internally.
- Exposes commonly used Sprite properties such as image/color/flip/draw mode/blend.
import { Engine, EngineConfiguration, UIScene, UIImageView, ImageAsset, WorldNode, Pivot, Vector2, Rect, Color } from "./build/vanilla.js";
class MainScene extends UIScene {
constructor() {
super();
this.setLoadingMinDurationMs(0);
this.imageAsset = null;
}
async loadAssets() {
await super.loadAssets();
const imageAsset = new ImageAsset();
await imageAsset.load("examples/assets/spritesheet.png");
this.imageAsset = imageAsset;
}
initialize(engine) {
super.initialize(engine);
const iconNode = new WorldNode();
iconNode.setPivot(Pivot.topLeft);
iconNode.setAnchor(Pivot.topLeft);
iconNode.setLocalPosition(Vector2.create(40, 40));
iconNode.setContentSize(Vector2.create(120, 120));
const imageView = iconNode.addComponent(UIImageView);
imageView.setImage(this.imageAsset);
imageView.setImageRect(Rect.create(0, 0, 200, 200));
imageView.setColor(new Color(1, 0.5, 0, 0.4));
const root = this.getRoot();
root.addChild(iconNode);
}
}
const engineConfiguration = new EngineConfiguration();
engineConfiguration.canvasId = "mainCanvas";
engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
engineConfiguration.autoResizeOnWindowResize = true;
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());노드에 붙음. (내부 Sprite 컴포넌트 부착)
Attached to a node. (attaches the internal Sprite component)
- nodeComponentNode
- 붙을 노드.Node to attach to.
노드에서 떨어짐. (내부 Sprite 컴포넌트 제거)
Detached from a node. (removes the internal Sprite component)
- nodeComponentNode
- 떨어질 노드.Node being detached from.
내부 Sprite 컴포넌트 반환. (디테일 제어가 필요할 때 직접 접근)
Returns the internal Sprite component. (for direct access when fine control is needed)
반환ReturnsSprite | null 내부 Sprite. (노드에 붙기 전이나 떨어진 뒤면 null)The internal Sprite. (null before attaching or after detaching)
짝Counterpart: vanilla-engine UIImageView.get_sprite
이미지 설정. (HTMLImageElement / OffscreenCanvas / ImageAsset 모두 허용)
Sets the image. (HTMLImageElement / OffscreenCanvas / ImageAsset are all allowed)
- imageHTMLImageElement | OffscreenCanvas | ImageAsset | null
- 그릴 그림. (ImageAsset 이면 그 image, null 이면 비운다, 노드에 붙기 전이면 무시한다)Image to draw. (for an ImageAsset its image, clears if null, ignored before being attached to a node)
짝Counterpart: vanilla-engine UIImageView.set_image
이미지 반환.
Returns the image.
반환ReturnsHTMLImageElement | OffscreenCanvas | null 지금 그림. (없거나 노드에 붙기 전이면 null)The current image. (null if none or before being attached to a node)
짝Counterpart: vanilla-engine UIImageView.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 UIImageView.set_image_path
그림 경로 반환. (정하지 않았으면 빈 글)
Returns the image path. (empty string if not set)
반환Returnsstring 그림 경로. (정하지 않았으면 빈 글)Image path. (empty string if not set)
짝Counterpart: vanilla-engine UIImageView.get_image_path
이미지 부분 영역(소스 사각형) 설정.
Sets the image sub-region (source rectangle).
- imageRectRect
- 그림에서 잘라 그릴 영역. (그림의 픽셀, 빈 사각형이면 그림 전체, simple 과 tiled 모드에서 쓴다)Area of the image to cut out and draw. (image pixels, the whole image if the rectangle is empty, used in simple and tiled modes)
짝Counterpart: vanilla-engine UIImageView.set_image_rect
색상 설정. (스프라이트 틴트)
Sets the color. (sprite tint)
- colorColor | string
- 틴트 색. (알파가 0 보다 크면 그림의 실루엣 안을 이 색으로 덮는다, 그림이 없으면 내용 영역을 이 색으로 칠한다, 기본 투명)Tint color. (if alpha is above 0, covers the inside of the image silhouette with this color, fills the content area with this color if there is no image, default transparent)
짝Counterpart: vanilla-engine UIImageView.set_color
색상 반환. (스프라이트 틴트, 스프라이트가 없으면 null)
Returns the color. (sprite tint, null if there is no sprite)
반환ReturnsColor | null 틴트 색. (노드에 붙기 전이면 null)Tint color. (null before being attached to a node)
짝Counterpart: vanilla-engine UIImageView.get_color
가로 플립 설정.
Sets horizontal flip.
- isHorizontalFlipboolean
- 참이면 좌우로 뒤집어 그린다.If true, draws flipped horizontally.
짝Counterpart: vanilla-engine UIImageView.set_horizontal_flip
세로 플립 설정.
Sets vertical flip.
- isVerticalFlipboolean
- 참이면 위아래로 뒤집어 그린다.If true, draws flipped vertically.
짝Counterpart: vanilla-engine UIImageView.set_vertical_flip
드로우 모드 설정. (simple / sliced / tiled)
Sets the draw mode. (simple / sliced / tiled)
- modestring
- 그리기 모드. (simple, sliced, tiled 가운데 하나, 기본 simple)Draw mode. (one of simple, sliced, tiled, default simple)
짝Counterpart: vanilla-engine UIImageView.set_draw_mode
블렌드 모드 설정.
Sets the blend mode.
- modestring
- 블렌드 모드. (Canvas2D globalCompositeOperation 이름, 기본 source-over)Blend mode. (a Canvas2D globalCompositeOperation name, default source-over)
짝Counterpart: vanilla-engine UIImageView.set_blend_mode
나인패치 영역 설정.
Sets the nine-patch region.
- nineSliceRect
- 나인 슬라이스 테두리 두께. (position.x 왼쪽, position.y 위, size.x 오른쪽, size.y 아래, 그림의 픽셀, sliced 모드에서 그림 전체를 나눈다)Nine-slice border thickness. (position.x left, position.y top, size.x right, size.y bottom, in image pixels, splits the whole image in sliced mode)
짝Counterpart: vanilla-engine UIImageView.set_nine_slice
import { Engine, EngineConfiguration, UIScene, UIImageView, ImageAsset, WorldNode, Pivot, Vector2, Rect } from "./build/vanilla.js";
class MainScene extends UIScene {
constructor() {
super();
this.setLoadingMinDurationMs(0);
this.imageAsset = null;
}
async loadAssets() {
await super.loadAssets();
const imageAsset = new ImageAsset();
await imageAsset.load("assets/icons/icon.png");
this.imageAsset = imageAsset;
}
initialize(engine) {
super.initialize(engine);
const panelNode = new WorldNode();
panelNode.setPivot(Pivot.topLeft);
panelNode.setAnchor(Pivot.topLeft);
panelNode.setLocalPosition(Vector2.create(40, 40));
panelNode.setContentSize(Vector2.create(400, 160));
const imageView = panelNode.addComponent(UIImageView);
imageView.setImage(this.imageAsset);
imageView.setDrawMode("sliced");
imageView.setNineSlice(Rect.create(64, 64, 64, 64));
const root = this.getRoot();
root.addChild(panelNode);
}
}
const engineConfiguration = new EngineConfiguration();
engineConfiguration.canvasId = "mainCanvas";
engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
engineConfiguration.autoResizeOnWindowResize = true;
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());