vanilladocs
vanillapunch.com
API / misc/toucheffect

misc/toucheffect

터치 효과 컴포넌트.

  • 원본 misc/toucheffect.js 를 옮긴 것이다. 누른 자리에 하늘색 빛 입자를 흩뿌리고 0.4 초 동안 흐려지며 퍼지게 한다.
  • 입자는 흰색 방사형 그라디언트 그림(64x64, 한 번만 만든다)을 하늘색(rgb 100, 200, 255)으로 틴트하고 더하기(lighter) 블렌드로 그린다.
  • 사용:
let touch_effect_id = node_tree.create_child(root_id, "TouchEffect");
node_tree[touch_effect_id].set_pivot(Pivot::TOP_LEFT);
node_tree[touch_effect_id].add_component(TouchEffect::new());
// 누를 때: node_tree[touch_effect_id].get_component_mut::<TouchEffect>().unwrap().create_touch_particle(x, y);
  • 원본과 다른 점: 원본은 WorldNode 를 상속한 노드이고, 러스트 판은 노드에 붙는 컴포넌트다. 블렌드는 원본처럼 push_transform 에서 더하기로 바꾸고 pop_transform 에서 앞의 블렌드로 되돌려 자식까지 더하기로 그린다. (컴포넌트의 노드 출력 상태 앞뒤 훅) 그라디언트는 원본처럼 오프스크린 캔버스(엔진 Canvas2D)의 방사 그라디언트로 구운 Image 다.

Touch effect component.

  • A port of the original misc/toucheffect.js. Scatters sky blue light particles at the press point that fade and spread over 0.4 seconds.
  • Particles draw a white radial gradient image (64x64, made only once) tinted sky blue (rgb 100, 200, 255) with additive (lighter) blending.
  • Usage:
let touch_effect_id = node_tree.create_child(root_id, "TouchEffect");
node_tree[touch_effect_id].set_pivot(Pivot::TOP_LEFT);
node_tree[touch_effect_id].add_component(TouchEffect::new());
// on press: node_tree[touch_effect_id].get_component_mut::<TouchEffect>().unwrap().create_touch_particle(x, y);
  • Differences from the original: The original is a node that inherits WorldNode, and the Rust version is a component attached to a node. As in the original, the blend is switched to additive in push_transform and restored to the previous blend in pop_transform, so children are drawn additively too. (the component's hooks around the node draw state) The gradient is an Image baked with the radial gradient of an offscreen canvas (the engine Canvas2D), like the original.

TouchParticlestruct traits Clone, Copy, Debug, PartialEq, Default

짝Counterpart: vanilla.js TouchParticle소스source

터치 입자.

  • TouchEffect 가 목록으로 든다. 값만 담는 구조체다.

Touch particle.

  • TouchEffect holds them in a list. A struct holding only values.
예제Example입자 하나의 값Values of one particle
use vanilla::{TouchParticle, Vector2};

let mut particle = TouchParticle::new();
particle.position = Vector2::create(40.0, 30.0);
particle.radius = 20.0;
assert_eq!(particle.life, particle.max_life);
assert_eq!(particle.velocity, Vector2::zero());
생성자constructorpub fn new() -> TouchParticle#0.3.2 부터since 0.3.2소스source

생성. (제자리, 수명 1, 반지름 0)

Constructor. (stationary, life 1, radius 0)

반환ReturnsTouchParticle 위치와 속도가 0, 수명과 처음 수명이 1, 반지름이 0 인 입자.A particle with position and velocity 0, life and initial life 1, and radius 0.

짝Counterpart: vanilla.js TouchParticle.constructor

필드fieldpub position: Vector2#0.3.2 부터since 0.3.2소스source

가운데 위치. (노드 영역 좌표, 픽셀)

Center position. (node area coordinates, pixels)

반환ReturnsVector2

짝Counterpart: vanilla.js TouchParticle.position

필드fieldpub velocity: Vector2#0.3.2 부터since 0.3.2소스source

속도. (픽셀/초)

Velocity. (pixels/second)

반환ReturnsVector2

짝Counterpart: vanilla.js TouchParticle.velocity

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

남은 수명. (TouchEffect 에서 1 로 시작해 초당 2.5 씩 줄고, 0 이하면 빠진다)

Remaining life. (starts at 1 in TouchEffect, decreases by 2.5 per second, removed at 0 or less)

반환Returnsf64

짝Counterpart: vanilla.js TouchParticle.life

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

처음 수명. (그릴 때 투명도는 life / max_life)

Initial life. (opacity when drawn is life / max_life)

반환Returnsf64

짝Counterpart: vanilla.js TouchParticle.maxLife

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

반지름. (픽셀)

Radius. (pixels)

반환Returnsf64

짝Counterpart: vanilla.js TouchParticle.radius

TouchEffectstruct traits Default, Component, UIDocumentNode

짝Counterpart: vanilla.js TouchEffect소스source

터치 효과 컴포넌트.

  • 누를 때 create_touch_particle 을 부르면 tick 에서 입자를 줄이고 draw 에서 더하기 블렌드로 그린다.

Touch effect component.

  • If create_touch_particle is called on press, tick wears the particles down and draw renders them with additive blending.
예제Example노드에 붙이고 누른 자리에 입자 만들기Attach to a node and make particles at the press point
use vanilla::{NodeTree, Pivot, TouchEffect};

let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let touch_effect_id = node_tree.create_child(root_id, "TouchEffect");
node_tree[touch_effect_id].set_pivot(Pivot::TOP_LEFT);
node_tree[touch_effect_id].add_component(TouchEffect::new());

let touch_effect = node_tree[touch_effect_id].get_component_mut::<TouchEffect>().unwrap();
touch_effect.create_touch_particle(120.0, 80.0);
assert_eq!(touch_effect.get_particle_count(), 1);
touch_effect.update_touch_particles(0.5);
assert_eq!(touch_effect.get_particle_count(), 0);
생성자constructorpub fn new() -> TouchEffect#0.3.2 부터since 0.3.2소스source

생성.

Constructor.

반환ReturnsTouchEffect 입자가 없는 새 터치 효과.A new touch effect with no particles.

짝Counterpart: vanilla.js TouchEffect.constructor

메서드methodpub fn create_touch_particle(&mut self, x: f64, y: f64)#0.3.2 부터since 0.3.2소스source

터치 입자 만들기. (노드 영역 좌표, ±5 픽셀 흩뿌림, ±60 픽셀/초 속도, 반지름 10 ~ 35)

Creates touch particles. (node area coordinates, ±5 pixel scatter, ±60 pixels/second velocity, radius 10 ~ 35)

xf64
누른 자리 x. (노드 영역 좌표, 픽셀)Press point x. (node area coordinates, pixels)
yf64
누른 자리 y. (노드 영역 좌표, 픽셀)Press point y. (node area coordinates, pixels)

짝Counterpart: vanilla.js TouchEffect.createTouchParticle

메서드methodpub fn update_touch_particles(&mut self, time_delta: f64)#0.3.2 부터since 0.3.2소스source

터치 입자 갱신. (수명이 초당 2.5 씩 줄고, 다 되면 뺀다)

Updates the touch particles. (life decreases by 2.5 per second, removed when used up)

time_deltaf64
지난 시간. (초, 위치는 속도 * time_delta 만큼 움직인다)Elapsed time. (seconds, the position moves by velocity * time_delta)

짝Counterpart: vanilla.js TouchEffect.updateTouchParticles

메서드methodpub fn draw_touch_particles(&self, graphic: &mut Graphic)#0.3.2 부터since 0.3.2소스source

터치 입자 출력. (흰색 그라디언트를 입자 색으로 틴트하고, 남은 수명만큼 흐리게)

  • 블렌드는 바꾸지 않는다. (컴포넌트로 그릴 때는 push_transform 이 더하기로 바꾼다)

Draws the touch particles. (tints the white gradient with the particle color, faded by the remaining life)

  • Does not change the blend. (when drawn as a component, push_transform switches it to additive)
graphic&mut Graphic
그릴 그래픽. (이미지 틴트와 전역 알파는 그린 뒤 되돌린다)Graphic to draw to. (image tint and global alpha are restored after drawing)

짝Counterpart: vanilla.js TouchEffect.drawTouchParticles

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

살아 있는 입자 수. (러스트 판에서 더한 것)

Number of live particles. (added in the Rust version)

반환Returnsusize 수명이 남은 입자 수.Number of particles with life remaining.