vanilladocs
vanillapunch.com
API / ui/uitoast

ui/uitoast

토스트.

Toast.

UIToastextends WorldNode

짝Counterpart: vanilla-engine UIToast

토스트.

  • show(message) 로 알약 모양 알림이 아래에서 떠올라 잠시 머문 뒤 사라진다.
  • 여러 번 부르면 줄을 세워 하나씩 보여 준다. (여러 게임이 화면마다 복붙하던 패턴)
  • 씬 뿌리의 맨 위(마지막 자식)에 addChild 해 두고 쓴다.
  • 사용:
const toast = new UIToast();
scene.getRoot().addChild(toast);
toast.show("저장되었습니다.");

Toast.

  • show(message) makes a pill-shaped notification rise from the bottom, stay briefly, then disappear.
  • Calling it several times queues them and shows them one by one. (a pattern several games copy-pasted per screen)
  • addChild it at the top (last child) of the scene root before use.
  • Usage:
const toast = new UIToast();
scene.getRoot().addChild(toast);
toast.show("Saved.");
예제Example알림 두 개를 줄 세워 띄우기Queuing two notifications
import { Engine, EngineConfiguration, UIScene, UIToast, Color } from "./build/vanilla.js";

class ToastScene extends UIScene {
	create() {
		super.create();
		const toast = new UIToast({ width: 320, height: 40, restY: 300, holdSeconds: 1.2, backgroundColor: new Color(0.07, 0.09, 0.13, 0.95) });
		const root = this.getRoot();
		root.addChild(toast);
		toast.show("Game saved");
		toast.show("Achievement unlocked");
		const isShowing = toast.isShowing();
		console.log(isShowing);
	}
}

const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
const scene = new ToastScene();
scene.setLoadingMinDurationMs(0);
engine.run(scene);
생성자constructorconstructor(options = {})#0.3.0 부터since 0.3.0소스source

생성.

Constructor.

optionsobject
{ width = 400, height = 48, restY = 560, holdSeconds = 1.8, backgroundColor?, textColor? }

짝Counterpart: vanilla-engine UIToast.new

메서드methodshow(messageText)#0.3.0 부터since 0.3.0소스source

토스트 표시. (표시 중이면 줄을 선다)

Shows a toast. (queued if one is showing)

messageTextstring
알림 글. (떠 있는 것이 없으면 곧바로 띄우고, 있으면 줄 끝에 넣는다)Notification text. (shown right away if nothing is shown, otherwise added to the end of the queue)

짝Counterpart: vanilla-engine UIToast.show

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

갱신.

Update.

timeDeltanumber
지난 프레임부터의 시간. (초, 나오기 0.24 초, 머물기 holdSeconds, 사라지기 0.2 초)Time since the last frame. (seconds, enter 0.24 seconds, hold holdSeconds, exit 0.2 seconds)
메서드methodsetRestY(restY)#0.3.0 부터since 0.3.0소스source

표시 자리(가운데 세로 좌표) 설정.

Sets the display position (center vertical coordinate).

restYnumber
머무는 자리의 가운데 세로 좌표. (부모 로컬 픽셀, 나올 때 28 픽셀 아래에서 떠오른다)Vertical center coordinate of the resting position. (parent local pixels, rises from 28 pixels below when entering)

짝Counterpart: vanilla-engine UIToast.set_rest_y

메서드methodsetRestX(restX)#0.3.0 부터since 0.3.0소스source

표시 자리(가운데 가로 좌표) 설정. (null 이면 부모 가로 중앙)

Sets the display position (center horizontal coordinate). (null means the parent's horizontal center)

restXnumber | null
가운데 가로 좌표. (부모 로컬 픽셀, null 이면 부모 너비의 반, 부모 크기가 0 이면 480)Horizontal center coordinate. (parent local pixels, half the parent width if null, 480 if the parent size is 0)

짝Counterpart: vanilla-engine UIToast.set_rest_x

메서드methodsetHoldSeconds(holdSeconds)#0.3.0 부터since 0.3.0소스source

머무는 시간 설정.

Sets the stay duration.

holdSecondsnumber
머무는 초. (다 나온 뒤부터 센다)Seconds to stay. (counted after it has fully entered)

짝Counterpart: vanilla-engine UIToast.set_hold_seconds

메서드methodisShowing()#0.3.0 부터since 0.3.0소스source

표시 중 여부.

Whether it is showing.

반환Returnsboolean 나오는 중, 머무는 중, 사라지는 중이면 참.True while entering, staying or exiting.

짝Counterpart: vanilla-engine UIToast.is_showing