ui/uibutton
버튼.
Button.
UIButtonextends UIControl
버튼.
Button.
import { Engine, EngineConfiguration, UIScene, UIButton, UILabel, Paint, WorldNode, Pivot, Vector2, Color } from "./build/vanilla.js";
class MainScene extends UIScene {
constructor() {
super();
this.setLoadingMinDurationMs(0);
}
initialize(engine) {
super.initialize(engine);
const buttonNode = new WorldNode();
buttonNode.setPivot(Pivot.topLeft);
buttonNode.setAnchor(Pivot.topLeft);
buttonNode.setLocalPosition(Vector2.create(40, 40));
buttonNode.setContentSize(Vector2.create(200, 60));
const paint = buttonNode.addComponent(Paint);
paint.setColor(new Color(0.2, 0.45, 0.85, 1));
paint.setRoundSize(12);
const label = buttonNode.addComponent(UILabel);
label.setText("Start");
label.setFontSize(24);
const button = buttonNode.addComponent(UIButton);
button.setPressedTintColor(new Color(0, 0, 0, 0.35));
button.setTransitionDuration(0.15);
button.setClickedEvent((clickedButton) => {
console.log("start", clickedButton.getButtonState());
});
const root = this.getRoot();
root.addChild(buttonNode);
}
}
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());트랜지션 대상에서 노드를 제외. 해당 노드 자신과 모든 자손 노드의 컴포넌트가 색상 수집에서 제외된다.
Excludes a node from transition targets. The components of the node itself and all its descendant nodes are excluded from color collection.
- nodeComponentNode
- 틴트에서 뺄 노드. (자손 노드까지 빠진다)Node to exclude from the tint. (its descendants are excluded too)
짝Counterpart: vanilla-engine UIButton.exclude_node_from_tint
import { Engine, EngineConfiguration, UIScene, UIButton, Paint, WorldNode, Pivot, Vector2, Color } from "./build/vanilla.js";
class MainScene extends UIScene {
constructor() {
super();
this.setLoadingMinDurationMs(0);
}
initialize(engine) {
super.initialize(engine);
const buttonNode = new WorldNode();
buttonNode.setPivot(Pivot.topLeft);
buttonNode.setAnchor(Pivot.topLeft);
buttonNode.setLocalPosition(Vector2.create(40, 40));
buttonNode.setContentSize(Vector2.create(200, 60));
const paint = buttonNode.addComponent(Paint);
paint.setColor(new Color(0.2, 0.45, 0.85, 1));
const badgeNode = new WorldNode();
badgeNode.setPivot(Pivot.topLeft);
badgeNode.setAnchor(Pivot.topLeft);
badgeNode.setLocalPosition(Vector2.create(176, -8));
badgeNode.setContentSize(Vector2.create(24, 24));
const badgePaint = badgeNode.addComponent(Paint);
badgePaint.setColor(new Color(0.9, 0.2, 0.2, 1));
badgePaint.setRoundSize(12);
buttonNode.addChild(badgeNode);
const button = buttonNode.addComponent(UIButton);
button.excludeNodeFromTint(badgeNode);
const root = this.getRoot();
root.addChild(buttonNode);
}
}
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());트랜지션 대상에서 특정 컴포넌트만 제외.
Excludes only a specific component from transition targets.
- componentComponent
- 틴트에서 뺄 컴포넌트.Component to exclude from the tint.
짝Counterpart: vanilla-engine UIButton.exclude_component_from_tint
제외 목록 초기화.
Clears the exclusion list.
짝Counterpart: vanilla-engine UIButton.clear_tint_exclusions
노드에 붙음. (노드의 isInteractable 을 자동 활성화, WorldNode 와 UINode)
Attached to a node. (turns on the node's isInteractable automatically, WorldNode and UINode)
- nodeComponentNode
- 붙을 노드.Node to attach to.
갱신.
Update.
- timeDeltanumber
- 지난 프레임부터의 시간. (초)Time since the last frame. (Seconds)
마우스 오버 상태 갱신.
- 누르고 있는 중이거나 사용 불가일 때는 건드리지 않는다.
- 엔진 인스턴스는 전역 접근자로 얻어 순환 참조를 만들지 않는다.
Updates the mouse-over state.
- Does not touch it while pressed or when unusable.
- Gets the engine instance via the global accessor so as not to create circular references.
내용 영역 안에서만 그리는지 반환. (버튼은 스스로 그리지 않는다, 화면 밖과 자르기 밖 거르기가 쓴다)
- draw 를 덮어쓴 하위 클래스는 어디에 그리는지 모르므로 false. (그 클래스가 이 함수도 덮어써 알린다)
Returns whether it draws only inside the content area. (the button draws nothing itself; used by off-screen and outside-clip culling)
- Subclasses that override draw return false because where they draw is unknown. (such a class overrides this function too to report it)
반환Returnsboolean 내용 영역 안에서만 그리면 참.True if drawing only inside the content area.
터치 누름. (TouchRaycaster → WorldNode → Button)
Touch press. (TouchRaycaster → WorldNode → Button)
- viewInputPositionVector2
- 누른 자리. (뷰 좌표)Press position. (view coordinates)
터치 뗌. (TouchRaycaster → WorldNode → Button)
Touch release. (TouchRaycaster → WorldNode → Button)
- viewInputPositionVector2
- 뗀 자리. (뷰 좌표)Release position. (view coordinates)
뗌 처리 본문.
Release handling body.
- viewInputPositionVector2
- 뗀 자리. (뷰 좌표, 노드 안이면 클릭으로 친다)Release position. (view coordinates, counts as a click if inside the node)
클릭 알림만 부르기. (누르지 않고 클릭이 난 것처럼 clicked, click 차례로, UIHitArea 가 넓힌 자리의 클릭을 넘길 때)
Calls only the click notifications. (clicked, then click, as if a click happened without a press; used when UIHitArea passes on a click on its widened area)
짝Counterpart: vanilla-engine UIButton.fire_click_events
터치 취소. (TouchRaycaster → WorldNode → Button)
Touch cancel. (TouchRaycaster → WorldNode → Button)
- viewInputPositionVector2
- 취소된 때의 자리. (뷰 좌표)Position at cancel. (view coordinates)
틴트 적용.
Applies the tint.
- progressnumber
- 틴트 정도. (0 이면 원래 색, 1 이면 틴트 색을 다 씌운다)Tint amount. (0 is the original color, 1 applies the full tint color)
색상 대상 수집.
Collects color targets.
노드에서 색상 대상 재귀 수집.
- excludeNodeFromTint 로 등록된 노드는 자신과 자손까지 통째로 건너뛴다.
- excludeComponentFromTint 로 등록된 컴포넌트는 개별적으로 제외한다.
Recursively collects color targets from a node.
- Nodes registered with excludeNodeFromTint are skipped entirely, along with their descendants.
- Components registered with excludeComponentFromTint are excluded individually.
- nodeComponentNode
- 훑을 노드. (자식들도 차례로 훑는다)Node to walk. (its children are walked in turn)
버튼 상태 변경.
Changes the button state.
- buttonStateButtonState
- 버튼 상태. (ButtonState 의 값)Button state. (a ButtonState value)
짝Counterpart: vanilla-engine UIButton.set_button_state
버튼 상태 반환.
Returns the button state.
반환ReturnsButtonState 지금 버튼 상태. (ButtonState 의 값)The current button state. (a ButtonState value)
짝Counterpart: vanilla-engine UIButton.get_button_state
길게 누름 알림 설정. (임계 시간을 넘기면 한 번 알리고, 그 누름의 클릭은 삼킨다)
Set the long press notification. (notifies once when the threshold time passes and swallows the click of that press)
- longPressedEventfunction(UIButton): void
- 길게 누르면 한 번 부를 함수. (인자는 이 버튼, null 이면 길게 누름을 보지 않는다)Function called once on a long press. (the argument is this button, long presses are not detected if null)
짝Counterpart: vanilla-engine UIButton.set_long_pressed_event
import { Engine, EngineConfiguration, UIScene, UIButton, Paint, WorldNode, Pivot, Vector2, Color } from "./build/vanilla.js";
class MainScene extends UIScene {
constructor() {
super();
this.setLoadingMinDurationMs(0);
this.button = null;
}
initialize(engine) {
super.initialize(engine);
const itemNode = new WorldNode();
itemNode.setPivot(Pivot.topLeft);
itemNode.setAnchor(Pivot.topLeft);
itemNode.setLocalPosition(Vector2.create(40, 40));
itemNode.setContentSize(Vector2.create(96, 96));
const paint = itemNode.addComponent(Paint);
paint.setColor(new Color(0.3, 0.3, 0.35, 1));
const button = itemNode.addComponent(UIButton);
button.setLongPressSeconds(0.8);
button.setLongPressedEvent(() => {
console.log("delete item");
});
button.setClickedEvent(() => {
console.log("open item");
});
this.button = button;
const root = this.getRoot();
root.addChild(itemNode);
}
tick(timeDelta) {
super.tick(timeDelta);
if (this.button !== null) {
const pressedSeconds = this.button.getPressedElapsedSeconds();
const longPressSeconds = this.button.getLongPressSeconds();
const gaugeRatio = Math.min(1, pressedSeconds / longPressSeconds);
if (gaugeRatio > 0) {
console.log("hold", gaugeRatio);
}
}
}
}
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());길게 누름 판정 시간 설정. (초)
Sets the long press threshold time. (seconds)
- longPressSecondsnumber
- 길게 누름으로 볼 시간. (초, 기본 0.5)Time that counts as a long press. (seconds, default 0.5)
짝Counterpart: vanilla-engine UIButton.set_long_press_seconds
이번 누름이 이어진 시간 반환. (게이지 연출용)
Returns how long the current press has lasted. (for gauge effects)
반환Returnsnumber 이번 누름이 이어진 시간. (초, 누르고 있지 않으면 0)How long the current press has lasted. (seconds, 0 if not pressed)
짝Counterpart: vanilla-engine UIButton.get_pressed_elapsed_seconds
길게 누름 판정 시간 반환.
Returns the long press threshold time.
반환Returnsnumber 길게 누름 판정 시간. (초)Long press threshold time. (seconds)
짝Counterpart: vanilla-engine UIButton.get_long_press_seconds
최소 눌림 표시 시간 설정. (짧게 톡 눌러도 이 시간만큼 눌린 모습을 보인 뒤 클릭을 부른다)
Sets the minimum pressed display time. (even a quick tap shows the pressed look for this long before calling the click)
- minimumPressedSecondsnumber
- 눌린 모습을 보여 줄 가장 짧은 시간. (초, 0 보다 작으면 0, 기본 0 이면 바로)Minimum time to show the pressed look. (seconds, 0 if below 0, default 0 means immediately)
짝Counterpart: vanilla-engine UIButton.set_minimum_pressed_seconds
최소 눌림 표시 시간 반환.
Returns the minimum pressed display time.
반환Returnsnumber 최소 눌림 표시 시간. (초)Minimum pressed display time. (seconds)
짝Counterpart: vanilla-engine UIButton.get_minimum_pressed_seconds
클릭 이벤트 설정.
Sets the click event.
- callbackfunction(UIButton): boolean
- 클릭이 나면 클릭됨 이벤트 다음에 부를 함수. (인자는 이 버튼, 돌려준 값은 쓰지 않는다, null 이면 부르지 않는다)Function called after the clicked event when a click happens. (the argument is this button, the return value is not used, not called if null)
짝Counterpart: vanilla-engine UIButton.set_click_event
클릭 이벤트 반환.
Returns the click event.
반환Returnsfunction(UIButton): boolean 클릭 이벤트 함수. (없으면 null)Click event function. (null if none)
짝Counterpart: vanilla-engine UIButton.get_click_event
누름 이벤트 설정.
Sets the press event.
- callbackfunction(UIButton): void
- 누르면 부를 함수. (인자는 이 버튼, 누를 수 없는 상태면 부르지 않는다)Function called on press. (the argument is this button, not called when not interactable)
짝Counterpart: vanilla-engine UIButton.set_pressed_event
누름 이벤트 반환.
Returns the press event.
반환Returnsfunction(UIButton): void 누름 이벤트 함수. (없으면 null)Press event function. (null if none)
짝Counterpart: vanilla-engine UIButton.get_pressed_event
뗌 이벤트 설정.
Sets the release event.
- callbackfunction(UIButton): void
- 누른 뒤 떼면 부를 함수. (인자는 이 버튼, 노드 밖에서 떼도 부른다)Function called on release after a press. (the argument is this button, called even when released outside the node)
짝Counterpart: vanilla-engine UIButton.set_released_event
뗌 이벤트 반환.
Returns the release event.
반환Returnsfunction(UIButton): void 뗌 이벤트 함수. (없으면 null)Release event function. (null if none)
짝Counterpart: vanilla-engine UIButton.get_released_event
클릭됨 이벤트 설정.
Sets the clicked event.
- callbackfunction(UIButton): void
- 누른 뒤 노드 안에서 떼면 부를 함수. (인자는 이 버튼, 길게 누름을 알렸으면 부르지 않는다, null 이면 부르지 않는다)Function called when released inside the node after a press. (the argument is this button, not called if a long press was notified, not called if null)
짝Counterpart: vanilla-engine UIButton.set_clicked_event
클릭됨 이벤트 반환.
Returns the clicked event.
반환Returnsfunction(UIButton): void 클릭됨 이벤트 함수. (없으면 null)Clicked event function. (null if none)
짝Counterpart: vanilla-engine UIButton.get_clicked_event
눌림 틴트 색상 설정.
Sets the pressed tint color.
- colorColor | string
- 마우스가 올라 있을 때 덮을 틴트 색. (사본을 담는다, 기본 new Color(1, 1, 1, 0.12))Tint color applied while the mouse is over it. (a copy is stored, default new Color(1, 1, 1, 0.12))
짝Counterpart: vanilla-engine UIButton.set_hover_tint_color
오버 틴트 색상 반환.
Returns the over tint color.
반환ReturnsColor 오버 틴트 색.Hover tint color.
짝Counterpart: vanilla-engine UIButton.get_hover_tint_color
오버 진입 이벤트 설정.
Sets the over enter event.
- callbackfunction(UIButton): void
- 마우스가 노드 위로 들어오면 부를 함수. (인자는 이 버튼)Function called when the mouse enters the node. (the argument is this button)
짝Counterpart: vanilla-engine UIButton.set_hover_event
오버 진입 이벤트 반환.
Returns the over enter event.
반환Returnsfunction(UIButton): void 오버 진입 이벤트 함수. (없으면 null)Hover enter event function. (null if none)
짝Counterpart: vanilla-engine UIButton.get_hover_event
눌림 틴트 색상 설정.
Sets the pressed tint color.
- colorColor | string
- 누르는 동안 덮을 틴트 색. (기본 new Color(0, 0, 0, 0.3))Tint color applied while pressed. (default new Color(0, 0, 0, 0.3))
짝Counterpart: vanilla-engine UIButton.set_pressed_tint_color
눌림 틴트 색상 반환.
Returns the pressed tint color.
반환ReturnsColor 눌림 틴트 색.Pressed tint color.
짝Counterpart: vanilla-engine UIButton.get_pressed_tint_color
트랜지션 지속 시간 설정.
Sets the transition duration.
- durationnumber
- 틴트가 다 씌워지거나 걷히는 데 걸리는 시간. (초, 기본 0.3)Time for the tint to fully apply or clear. (seconds, default 0.3)
짝Counterpart: vanilla-engine UIButton.set_transition_duration
트랜지션 지속 시간 반환.
Returns the transition duration.
반환Returnsnumber 트랜지션 지속 시간. (초)Transition duration. (seconds)
짝Counterpart: vanilla-engine UIButton.get_transition_duration
활성화 여부 설정.
Sets whether enabled.
- isInteractableboolean
- 거짓이면 누름을 받지 않고 스프라이트에 비활성 틴트를 덮는다. (기본 참)If false, ignores presses and covers sprites with the disabled tint. (default true)
짝Counterpart: vanilla-engine UIButton.set_interactable
활성화 여부 반환.
Returns whether enabled.
반환Returnsboolean 누름을 받으면 참.True if it accepts presses.
짝Counterpart: vanilla-engine UIButton.get_interactable
ButtonStateenum
버튼 상태.
Button state.
| 이름Name | 값Value | 설명Description |
|---|---|---|
normal | Enum.begin() | 평상시 상태.Normal state. |
hover | Enum.auto() | 포인터가 올라간 상태.Pointer is over the button. |
pressed | Enum.auto() | 눌려 있는 상태.Pressed state. |
released | Enum.auto() | 막 뗀 상태.Just released state. |
disabled | Enum.auto() | 눌러도 반응하지 않는 상태.Disabled state, ignores input. |