vanilladocs
vanillapunch.com
API / ui/buttonmotion

ui/buttonmotion

단추 반응. (올리면 커지고, 누르는 동안 줄고, 떼면 통 튀고, 누를 수 없으면 흔들림, 창 안은 커지지 않음, 8.1 절)

Button motion. (Grows on hover, shrinks while pressed, bounces on release, shakes when not pressable, does not grow inside windows, section 8.1)

ButtonMotionextends Component

짝Counterpart: vanilla-engine ButtonMotion

단추 반응. (올리면 커지고, 누르는 동안 줄고, 떼면 통 튀고, 누를 수 없으면 흔들림, 창 안은 커지지 않음, 8.1 절) 단추 노드에 UIButton 다음으로 붙이면, 프레임마다 그 단추의 상태를 읽어 노드를 가운데를 두고 키우고 줄인다. 색은 건드리지 않는다. (글 단추의 바탕과 글자 색은 화면의 코드가 정하고, 그림 단추는 UIButton 의 tint 가 맡음) 손가락이 주된 기기는 올림을 쓰지 않는다. (뗀 뒤에도 손가락 자리가 남아 올린 채로 보이지 않게) 반응이 없을 때는 노드의 자리와 크기를 건드리지 않아, 다른 곳이 같은 노드를 키우는 연출(나타날 때의 통 튐)과 겹치지 않는다. 노드가 커져도 커진 자리가 처음 자리를 다 덮으므로, 올림 판정이 경계에서 떨지 않는다. 꼴은 setStyle 로 단추마다 정하거나, 비워 두면 위 노드 가운데 setButtonMotionArea 로 꼴을 건 가장 가까운 것을 따르고, 없으면 보통이다. (창 안은 inset) inset 꼴에서 올린 동안은 단추 노드의 맨 밑 자식으로 흰 테 판과 밝힌 바탕 판을 둔다. (바탕이 보이지 않는 단추는 밝히지 않음, 그 둘만은 이 부품이 색을 정함)

Button motion. (Grows on hover, shrinks while pressed, bounces on release, shakes when not pressable, does not grow inside windows, section 8.1) When attached to a button node after UIButton, reads the button's state every frame and scales the node up and down around its center. Does not touch colors. (The background and text colors of text buttons are set by the screen's code, and image buttons are handled by UIButton's tint) Devices where touch is primary do not use hover. (So the button does not look hovered because the finger position remains after release) When there is no motion, the node's position and size are left untouched, so it does not conflict with other effects that scale the same node (the bounce on appearance). Even when the node grows, the enlarged area fully covers the original area, so hover detection does not flicker at the edge. The style is set per button with setStyle, or if left empty, follows the nearest ancestor node whose style was set with setButtonMotionArea, otherwise normal. (inset inside windows) In the inset style, while hovered, a white border panel and a highlighted background panel are placed as the bottommost children of the button node. (Buttons with no visible background are not highlighted, and only for those two does this component set the color)

예제Example눌러지는 단추와 누를 수 없을 때 흔들기A pressable button and shaking when it cannot be pressed
import { Engine, EngineConfiguration, UIScene, UIButton, UILabel, Paint, WorldNode, Color, Pivot, Vector2, attachButtonMotion, shakeButton } from "./build/vanilla.js";

class ButtonMotionScene extends UIScene {
	create() {
		super.create();
		const buttonNode = new WorldNode();
		buttonNode.setName("BuyButton");
		buttonNode.setPivot(Pivot.topLeft.clone());
		buttonNode.setAnchor(Pivot.topLeft.clone());
		buttonNode.setContentSize(Vector2.create(160, 48));
		buttonNode.setLocalPosition(Vector2.create(240, 156));
		const buttonPaint = buttonNode.addComponent(Paint);
		buttonPaint.setColor(new Color(0.36, 0.42, 1, 1));
		buttonPaint.setRoundSize(10);
		const button = buttonNode.addComponent(UIButton);
		const buttonLabel = buttonNode.addComponent(UILabel);
		buttonLabel.setText("Buy");
		buttonLabel.setFontSize(18);
		attachButtonMotion(buttonNode);
		let coinCount = 40;
		button.setClickedEvent(() => {
			if (coinCount < 100) {
				shakeButton(buttonNode);
				return;
			}
			coinCount -= 100;
		});
		const root = this.getRoot();
		root.addChild(buttonNode);
		shakeButton(buttonNode);
	}
}

const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
const scene = new ButtonMotionScene();
scene.setLoadingMinDurationMs(0);
engine.run(scene);
생성자constructorconstructor()#0.4.0 부터since 0.4.0소스source

생성.

Constructor.

짝Counterpart: vanilla-engine ButtonMotion.new

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

이 단추의 꼴 정하기. (ButtonMotionStyle, 빈 글이면 위 노드에 건 꼴을 따름)

Sets this button's style. (ButtonMotionStyle, an empty string follows the style set on an ancestor node)

stylestring
꼴. (ButtonMotionStyle 의 값, 빈 글이면 위 노드에 건 꼴)Style. (a ButtonMotionStyle value, an empty string follows the style set on an ancestor node)

짝Counterpart: vanilla-engine ButtonMotion.set_style

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

이 단추가 따를 꼴. (정한 것, 없으면 위 노드에 건 가장 가까운 꼴, 그것도 없으면 보통)

The style this button follows. (The one set, otherwise the nearest style set on an ancestor node, otherwise normal)

nodeWorldNode
단추 노드. (부모부터 거슬러 오르며 setButtonMotionArea 로 건 꼴을 찾는다)Button node. (walks up from the parent to find a style set with setButtonMotionArea)

반환Returnsstring 따를 꼴. (ButtonMotionStyle 의 값)Style to follow. (a ButtonMotionStyle value)

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

붙음. (같은 노드의 단추를 찾아 둠)

Attached. (Finds and keeps the button on the same node)

nodeWorldNode
붙을 노드. (그 노드에 UIButton 이 없으면 반응하지 않는다)The node to attach to. (no reaction if that node has no UIButton)
메서드methodshake()#0.4.0 부터since 0.4.0소스source

누를 수 없을 때 흔들기. (누른 쪽에서 부른다)

Shakes when not pressable. (Called by the pressing side)

짝Counterpart: vanilla-engine ButtonMotion.shake

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

갱신. (단추 상태에 따라 크기를 맞추고, 노드의 가운데를 두고 놓음)

Update. (Adjusts the size by the button state and places the node around its center)

timeDeltanumber
지난 프레임부터의 시간. (초)Time since the last frame. (Seconds)
메서드methodmutePressTint(isMuted)#0.4.0 부터since 0.4.0소스source

단추의 눌림 색을 투명으로 바꾸거나 되돌리기. (글로시 껍데기가 눌림을 그리는 동안 투명, 껍데기를 끄면 정한 색)

Switches the button's pressed color to transparent or restores it. (Transparent while the glossy shell draws the press, the set color when the shell is turned off)

isMutedboolean
참이면 눌림 색의 알파를 0 으로, 거짓이면 처음 읽어 둔 눌림 색으로 되돌린다.If true, sets the pressed color's alpha to 0, if false, restores the pressed color read the first time.
메서드methodreadScrollPressed(node, buttonState)#0.4.0 부터since 0.4.0소스source

스크롤 칸 안에서 누르고 있는지. (엔진은 스크롤 칸 안 단추에 누르는 동안 눌림을 주지 않으므로, 누름이 이 단추 위에서 시작했고 손이 아직 단추 위이며 스크롤 칸이 밀리지 않았으면 눌린 것으로 그림, 밀리기 시작하면 풂)

Whether it is being pressed inside a scroll view. (The engine does not give the pressed state to buttons inside a scroll view while pressing, so it is drawn as pressed if the press started on this button, the pointer is still over the button and the scroll view has not scrolled, and released once scrolling starts)

nodeWorldNode
단추 노드.Button node.
buttonStatestring
단추 상태. (ButtonState 의 값, disabled 면 거짓)Button state. (a ButtonState value, false if disabled)

반환Returnsboolean 눌린 것으로 그릴 때 참. (스크롤 칸이나 엔진(System.vanillaEngine)이 없으면 거짓)True if it should be drawn as pressed. (false if there is no scroll view or engine (System.vanillaEngine))

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

단추를 담은 가장 가까운 스크롤 칸. (처음 한 번 위 노드를 거슬러 찾아 둠, 없으면 null)

The nearest scroll view containing the button. (Found once by walking up the ancestor nodes and kept, null if none)

nodeWorldNode
단추 노드.Button node.

반환ReturnsUIScrollView | null 가장 가까운 조상의 스크롤 칸. (없으면 null)Scroll view of the closest ancestor. (null if none)

메서드methodplaceLitParts(node, isLit, isPressed)#0.4.0 부터since 0.4.0소스source

밝힌 판 놓기. (흰 테 판은 단추 크기, 밝힌 바탕 판은 테 굵기만큼 안쪽, 둘 다 단추의 맨 밑 자식이라 글과 그림 밑)

Places the highlight panels. (The white border panel is the button size, the highlighted background panel is inset by the border thickness, both are the bottommost children of the button so they are below text and images)

nodeWorldNode
단추 노드.Button node.
isLitboolean
참이면 밝힌다. (단추 바탕 Paint 의 알파가 0 이면 밝히지 않는다)If true, it lights up. (does not light up if the alpha of the button's background Paint is 0)
isPressedboolean
누르는 중인지. (밝히는 함수에만 넘긴다)Whether it is being pressed. (passed only to the light handler)
메서드methodcreateLitParts(node)#0.4.0 부터since 0.4.0소스source

밝힌 판 만들기. (단추 노드의 맨 밑 자식 둘, 단추의 눌림 색은 받지 않음)

Creates the highlight panels. (Two bottommost children of the button node, they do not receive the button's pressed color)

nodeWorldNode
단추 노드. (맨 밑 자식 둘을 더한다)Button node. (adds two bottom-most children)

반환Returnsobject { ringNode, ringPaint, fillNode, fillPaint, fillColor }

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

손(마우스나 손가락)이 노드 위인지.

Whether the pointer (mouse or finger) is over the node.

nodeWorldNode
볼 노드.Node to look at.

반환Returnsboolean 입력 위치가 노드 안이면 참. (엔진(System.vanillaEngine)이 없으면 거짓)True if the input position is inside the node. (false if there is no engine (System.vanillaEngine))

메서드methodplaceAround(node, scale, shakeOffset)#0.4.0 부터since 0.4.0소스source

노드를 가운데를 두고 그 크기로 놓기. (노드는 왼쪽 위가 기준이라 커진 만큼 자리를 옮김)

  • 그 사이 화면이 노드를 다시 놓았으면(자리가 이 부품이 놓은 것과 다르면) 그 자리를 새 기준으로 삼는다.

Places the node at that size around its center. (The node is anchored at the top left, so it moves by the amount it grew)

  • If the screen has repositioned the node in the meantime (the position differs from the one this component set), that position becomes the new reference.
nodeWorldNode
단추 노드.Button node.
scalenumber
배율. (1 이 보통 크기)Scale. (1 is the normal size)
shakeOffsetnumber
가로로 밀 거리. (픽셀)Horizontal push distance. (pixels)
메서드methodsetLitHandler(litHandler)#0.4.0 부터since 0.4.0소스source

밝힘을 맡는 함수 설정. (단추에 얹은 꾸밈이 제 모양으로 밝힐 때, null 이면 이 부품이 흰 테 판과 밝힌 바탕 판을 둔다)

Sets the function that handles highlighting. (For when the decoration on the button highlights in its own shape, null means this component places the white border panel and the highlighted background panel)

litHandlerfunction(WorldNode, boolean, boolean): void | null
(단추 노드, 밝히는지, 누르는 중인지)(button node, whether highlighted, whether being pressed)

짝Counterpart: vanilla-engine ButtonMotion.set_lit_handler

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

밝힘을 맡는 함수 반환.

Returns the function that handles highlighting.

반환Returnsfunction(WorldNode, boolean, boolean): void | null 밝힘을 맡는 함수. (없으면 null)Function that handles lighting. (null if none)

짝Counterpart: vanilla-engine ButtonMotion.get_lit_handler

함수Functions

함수functionattachButtonMotion(node)#0.4.0 부터since 0.4.0소스source

단추 노드에 반응 붙이기. (UIButton 이 이미 붙은 노드, ButtonMotion 을 돌려줌)

Attaches motion to a button node. (A node with UIButton already attached, returns the ButtonMotion)

nodeWorldNode
UIButton 이 붙은 단추 노드.Button node with a UIButton attached.

반환ReturnsButtonMotion 붙인 반응 부품.The attached motion component.

짝Counterpart: vanilla-engine attach_button_motion

함수functionsetButtonMotionArea(node, style)#0.4.0 부터since 0.4.0소스source

노드 밑의 단추가 따를 꼴 걸기. (창이 제 판에 inset 을 걸면 그 안의 단추는 커지지 않음, 단추가 setStyle 로 정한 꼴이 먼저)

Sets the style that buttons under the node follow. (When a window sets inset on its panel, buttons inside it do not grow, a style set on the button with setStyle takes precedence)

nodeWorldNode
꼴을 걸 노드. (그 아래 모든 단추가 따른다)The node to set the style on. (all buttons below it follow)
stylestring
ButtonMotionStyle

짝Counterpart: vanilla-engine set_button_motion_area

예제Example판 안의 단추를 inset 꼴로Buttons inside a panel in the inset style
import { WorldNode, UIButton, ButtonMotionStyle, attachButtonMotion, setButtonMotionArea } from "./build/vanilla.js";

const panelNode = new WorldNode();
setButtonMotionArea(panelNode, ButtonMotionStyle.inset);
const buttonNode = new WorldNode();
buttonNode.addComponent(UIButton);
panelNode.addChild(buttonNode);
const buttonMotion = attachButtonMotion(buttonNode);
const areaStyle = buttonMotion.readMotionStyle(buttonNode);
console.log(areaStyle);
buttonMotion.setStyle(ButtonMotionStyle.normal);
const ownStyle = buttonMotion.readMotionStyle(buttonNode);
console.log(ownStyle);
함수functionshakeButton(node)#0.4.0 부터since 0.4.0소스source

누를 수 없는 단추를 흔들기. (반응이 붙은 단추만, 그 밖은 아무 일도 없음)

Shakes a button that cannot be pressed. (Only buttons with motion attached, nothing happens otherwise)

nodeWorldNode
ButtonMotion 이 붙은 단추 노드.Button node with a ButtonMotion attached.

짝Counterpart: vanilla-engine shake_button

ButtonMotionStyleenum

짝Counterpart: vanilla-engine ButtonMotionStyle

단추 반응의 꼴.

  • normal: 올리면 커지고, 누르는 동안 줄고, 떼면 통 튄다.
  • inset: 창 안의 단추. 1 배를 넘게 커지지 않아 창 안쪽 여백을 넘지 않는다. 올리면 바탕이 밝아지고 안쪽에 흰 테가 서며, 누르면 조금 줄었다 돌아온다.

Button motion style.

  • normal: grows on hover, shrinks while pressed, bounces on release.
  • inset: a button inside a window. Does not grow beyond 1x so it does not exceed the window's inner padding. On hover the background brightens and a white border appears inside, and on press it shrinks slightly and returns.
이름Name값Value설명Description
normalnormal올리면 커지고, 누르는 동안 줄고, 떼면 통 튄다.Grows on hover, shrinks while pressed and pops on release.
insetinset창 안의 단추. (커지지 않고, 올리면 바탕이 밝아지고 안쪽에 흰 테가 서며, 누르면 조금 줄었다 돌아온다)A button inside a window. (does not grow, on hover the background brightens and a white inner ring appears, and when pressed it shrinks slightly and comes back)