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
띄우기 설정. (원본 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 })
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);FloatingTextstruct traits Default, Component, UIDocumentNode
떠오르는 텍스트 관리 컴포넌트.
- 띄운 라벨은 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.
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);생성.
- 노드에 붙이지 않은 컴포넌트다. 보통은 노드까지 만들어 붙이는 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
노드 만들기. (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)
pub fn spawn(node_tree: &mut NodeTree, floating_text_node_id: NodeId, text: &str, world_position: Vector2, options: FloatingTextOptions) -> Option<NodeId>#텍스트 띄우기. (쉬는 라벨 노드가 있으면 다시 쓰고, 없으면 만든다. 띄운 라벨 노드를 돌려준다)
- 새 라벨 노드는 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
모두 지우기. (떠 있는 라벨을 끄고 쉬는 목록으로 돌린다)
- 노드를 지우지 않는다. 밖에서 지운 라벨은 목록에서만 뺀다. 컴포넌트가 없으면 아무것도 하지 않는다.
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
떠 있는 항목 수 반환.
Returns the number of floating items.
반환Returnsusize 아직 떠오르는 중인 라벨 수.Number of labels still rising.
짝Counterpart: vanilla.js FloatingText.getActiveCount