vanilladocs
vanillapunch.com
API / misc/floatingtext

misc/floatingtext

떠오르는 텍스트 관리 컴포넌트. (데미지 숫자 / +코인 등)

  • 원본 misc/floatingtext.js 를 옮긴 것이다. spawn 으로 띄우면 위로 떠오르며 사라지고, 끝난 라벨 노드는 다시 쓴다.
  • 씬 뿌리 밑에 노드 하나를 만들어 두고 월드 좌표로 띄운다.
  • 사용:
let floating_text_id = FloatingText::create(node_tree, root_id);
FloatingText::spawn(node_tree, floating_text_id, "-120", position, FloatingTextOptions { color: Color::create(1.0, 0.4, 0.4, 1.0), ..FloatingTextOptions::default() });
  • 원본과 다른 점: 원본은 WorldNode 를 상속한 노드다. 러스트 판은 노드에 붙는 컴포넌트이고, create 가 노드를 만들어 붙여 준다. spawn / clear 는 라벨 노드를 만들고 바꿔야 해서 트리와 노드 핸들을 받는 연관 함수다. (컴포넌트가 없으면 아무것도 하지 않는다) options 객체는 FloatingTextOptions 구조체다.

Floating text manager component. (damage numbers / +coins, etc.)

  • A port of the original misc/floatingtext.js. Text spawned with spawn rises and fades out, and finished label nodes are reused.
  • Create one node under the scene root and spawn in world coordinates.
  • Usage:
let floating_text_id = FloatingText::create(node_tree, root_id);
FloatingText::spawn(node_tree, floating_text_id, "-120", position, FloatingTextOptions { color: Color::create(1.0, 0.4, 0.4, 1.0), ..FloatingTextOptions::default() });
  • Differences from the original: The original is a node that inherits WorldNode. The Rust version is a component attached to a node, and create makes the node and attaches it. spawn / clear are associated functions that take the tree and a node handle because they must create and change label nodes. (they do nothing if the component is missing) The options object is the FloatingTextOptions struct.

FloatingTextOptionsstruct traits Clone, Copy, Debug, PartialEq, Default

소스source

띄우기 설정. (원본 options = { color?, font_size = 22, rise = 46, duration = 0.8, jitter = 10, bold = true })

Spawn settings. (original options = { color?, font_size = 22, rise = 46, duration = 0.8, jitter = 10, bold = true })

예제Example기본값에서 색과 높이만 바꾸기Change only the color and height from the defaults
use vanilla::{Color, FloatingTextOptions};

let options = FloatingTextOptions {
	color: Color::create(1.0, 0.4, 0.4, 1.0),
	rise: 60.0,
	..FloatingTextOptions::default()
};
assert_eq!(options.font_size, 22.0);
assert_eq!(options.duration, 0.8);
assert!(options.is_bold);
필드fieldpub color: Color#0.3.2 부터since 0.3.2소스source

글자 색. (기본 흰색)

Text color. (default white)

반환ReturnsColor

필드fieldpub font_size: f64#0.3.2 부터since 0.3.2소스source

글자 크기. (픽셀, 기본 22)

Font size. (pixels, default 22)

반환Returnsf64

필드fieldpub rise: f64#0.3.2 부터since 0.3.2소스source

떠오르는 높이. (픽셀)

Rise height. (pixels)

반환Returnsf64

필드fieldpub duration: f64#0.3.2 부터since 0.3.2소스source

사라질 때까지 걸리는 시간. (초)

Time until it disappears. (seconds)

반환Returnsf64

필드fieldpub jitter: f64#0.3.2 부터since 0.3.2소스source

가로로 흩뿌리는 폭. (±픽셀)

Horizontal scatter width. (±pixels)

반환Returnsf64

필드fieldpub is_bold: bool#0.3.2 부터since 0.3.2소스source

굵게 그릴지. (기본 true)

Whether to draw bold. (default true)

반환Returnsbool

FloatingTextstruct traits Default, Component, UIDocumentNode

짝Counterpart: vanilla.js FloatingText소스source

떠오르는 텍스트 관리 컴포넌트.

  • 띄운 라벨은 duration 동안 rise 만큼 감속하며 떠오르고 흐려진다. 다 끝난 라벨 노드는 꺼 두었다가 다음 spawn 이 다시 쓴다.

Floating text manager component.

  • A spawned label rises by rise while decelerating and fades over duration. Finished label nodes are turned off and reused by the next spawn.
예제Example데미지 숫자 띄우기Spawn a damage number
use vanilla::{Color, Engine, EngineConfiguration, FloatingText, FloatingTextOptions, NodeTree, UILabel, Vector2};

let engine = Engine::new(EngineConfiguration::new());
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let floating_text_id = FloatingText::create(&mut node_tree, root_id);
let options = FloatingTextOptions {
	color: Color::create(1.0, 0.4, 0.4, 1.0),
	..FloatingTextOptions::default()
};
let label_id = FloatingText::spawn(&mut node_tree, floating_text_id, "-120", Vector2::create(100.0, 200.0), options).unwrap();
assert_eq!(node_tree[label_id].get_component::<UILabel>().unwrap().get_text(), "-120");

node_tree.tick(&engine, 1.0);
assert!(!node_tree[label_id].is_active());
assert_eq!(node_tree[floating_text_id].get_component::<FloatingText>().unwrap().get_active_count(), 0);
생성자constructorpub fn new() -> FloatingText#0.3.2 부터since 0.3.2소스source

생성.

  • 노드에 붙이지 않은 컴포넌트다. 보통은 노드까지 만들어 붙이는 create 를 쓴다.

Constructor.

  • A component not attached to a node. Usually use create, which also makes the node and attaches it.

반환ReturnsFloatingText 떠 있는 항목이 없는 컴포넌트.A component with no floating items.

짝Counterpart: vanilla.js FloatingText.constructor

정적staticpub fn create(node_tree: &mut NodeTree, parent_id: NodeId) -> NodeId#0.3.2 부터since 0.3.2소스source

노드 만들기. (parent_id 밑에 "FloatingText" 노드를 만들고 컴포넌트를 붙인다. 원본 new FloatingText() + add_child)

  • 원본 생성자처럼 노드의 피벗과 앵커는 왼쪽 위다. (spawn 의 월드 좌표가 부모 왼쪽 위 기준)

Creates the node. (creates a "FloatingText" node under parent_id and attaches the component; the original new FloatingText() + add_child)

  • Like the original constructor, the node's pivot and anchor are top-left. (spawn's world position is relative to the parent's top-left)
node_tree&mut NodeTree
노드를 만들 트리.Tree to create the node in.
parent_idNodeId
부모 노드. (보통 씬 뿌리)Parent node. (usually the scene root)

반환ReturnsNodeId 만든 노드. (spawn, clear 에 넘긴다)The created node. (pass it to spawn, clear)

정적staticpub fn spawn(node_tree: &mut NodeTree, floating_text_node_id: NodeId, text: &str, world_position: Vector2, options: FloatingTextOptions) -> Option<NodeId>#0.3.2 부터since 0.3.2소스source

텍스트 띄우기. (쉬는 라벨 노드가 있으면 다시 쓰고, 없으면 만든다. 띄운 라벨 노드를 돌려준다)

  • 새 라벨 노드는 FloatingText 노드의 자식이고, 가운데 피봇, 240x40, Text 컴포넌트를 단다.

Spawns text. (reuses an idle label node if any, otherwise creates one. Returns the spawned label node)

  • A new label node is a child of the FloatingText node, with a center pivot, 240x40, and a Text component.
node_tree&mut NodeTree
라벨 노드를 만들거나 다시 쓸 트리.Tree to create or reuse label nodes in.
floating_text_node_idNodeId
FloatingText 컴포넌트가 붙은 노드. (create 가 돌려준 것)Node with the FloatingText component attached. (the one returned by create)
text&str
띄울 글.Text to show.
world_positionVector2
띄울 자리. (FloatingText 노드 안의 지역 좌표, 가로는 ±jitter 안에서 무작위로 흩뿌린다)Spawn position. (local coordinates within the FloatingText node, scattered randomly within ±jitter horizontally)
optionsFloatingTextOptions
색, 크기, 높이, 시간, 흩뿌림, 굵게.Color, size, height, duration, scatter, bold.

반환ReturnsOption<NodeId> 띄운 라벨 노드. 노드가 없거나 FloatingText 컴포넌트가 없으면 None.The spawned label node. None if the node or the FloatingText component is missing.

짝Counterpart: vanilla.js FloatingText.spawn

정적staticpub fn clear(node_tree: &mut NodeTree, floating_text_node_id: NodeId)#0.3.2 부터since 0.3.2소스source

모두 지우기. (떠 있는 라벨을 끄고 쉬는 목록으로 돌린다)

  • 노드를 지우지 않는다. 밖에서 지운 라벨은 목록에서만 뺀다. 컴포넌트가 없으면 아무것도 하지 않는다.

Clears all. (turns off the floating labels and returns them to the idle list)

  • Does not delete nodes. Labels deleted from outside are only removed from the list. Does nothing if the component is missing.
node_tree&mut NodeTree
라벨 노드가 든 트리.Tree containing the label nodes.
floating_text_node_idNodeId
FloatingText 컴포넌트가 붙은 노드.Node with the FloatingText component attached.

짝Counterpart: vanilla.js FloatingText.clear

메서드methodpub fn get_active_count(&self) -> usize#0.3.2 부터since 0.3.2소스source

떠 있는 항목 수 반환.

Returns the number of floating items.

반환Returnsusize 아직 떠오르는 중인 라벨 수.Number of labels still rising.

짝Counterpart: vanilla.js FloatingText.getActiveCount