pub struct Juice { /* private fields */ }Expand description
Bounded pool of presentation effects. See the module docs.
Implementations§
Source§impl Juice
impl Juice
Sourcepub fn with_capacity(sparks: usize, popups: usize, rings: usize) -> Juice
pub fn with_capacity(sparks: usize, popups: usize, rings: usize) -> Juice
A pool holding at most the given numbers of live effects (each at least 1).
Sourcepub fn set_motion(&mut self, motion: Motion)
pub fn set_motion(&mut self, motion: Motion)
Select full or reduced motion; reduced removes shake and drift.
Sourcepub fn set_words(&mut self, enabled: bool)
pub fn set_words(&mut self, enabled: bool)
Allow or ignore words: popups, callouts and toasts. Disable them for a background demonstration (for example behind a title screen) where floating text would collide with foreground copy; bursts, rings, confetti, shake and flashes still play.
use ferravex_render::{Color, juice::Juice, vec2};
let mut fx = Juice::new();
fx.set_words(false);
fx.popup(vec2(10., 10.), "+5", Color::new(1., 1., 1., 1.));
fx.burst(vec2(10., 10.), Color::new(1., 1., 1., 1.), 4);
assert_eq!(fx.counts().popups, 0);
assert!(fx.counts().sparks > 0);Sourcepub fn set_reduced_flash(&mut self, reduced: bool)
pub fn set_reduced_flash(&mut self, reduced: bool)
Keep flashes and vignettes faint for players who reduce flashing.
Sourcepub fn clear_words(&mut self)
pub fn clear_words(&mut self)
Remove floating words (popups, callouts and the toast) while keeping particles and rings, for example when a page or tab changes under them.
use ferravex_render::{Color, juice::Juice, vec2};
let mut fx = Juice::new();
fx.callout(vec2(10., 10.), "PERFECT", Color::new(1., 1., 1., 1.));
fx.ring(vec2(10., 10.), Color::new(1., 1., 1., 1.), 20.);
fx.clear_words();
assert_eq!((fx.counts().popups, fx.counts().rings), (0, 1));Sourcepub fn counts(&self) -> JuiceCounts
pub fn counts(&self) -> JuiceCounts
Live effect counts.
Sourcepub fn burst(&mut self, at: Vec2, color: Color, count: u32)
pub fn burst(&mut self, at: Vec2, color: Color, count: u32)
A radial spray of count round sparks from at, as for a hit, a
collected pickup or a completed task.
Sourcepub fn puff(&mut self, at: Vec2, color: Color, count: u32)
pub fn puff(&mut self, at: Vec2, color: Color, count: u32)
Soft rising, swelling puffs: steam, smoke, dust and breath. Unlike
Juice::burst they drift upward and grow as they fade.
use ferravex_render::{Color, juice::Juice, vec2};
let mut fx = Juice::new();
fx.puff(vec2(120., 200.), Color::new(0.9, 0.95, 1., 0.7), 8);
let before = fx.counts().sparks;
assert!(before > 0);Sourcepub fn sparkle(&mut self, at: Vec2, color: Color)
pub fn sparkle(&mut self, at: Vec2, color: Color)
A few twinkling four-point stars around at: rewards, selections, magic.
Sourcepub fn confetti(&mut self, at: Vec2, count: u32)
pub fn confetti(&mut self, at: Vec2, count: u32)
A celebratory shower of multicolored paper from at.
Sourcepub fn ring(&mut self, at: Vec2, color: Color, radius: f32)
pub fn ring(&mut self, at: Vec2, color: Color, radius: f32)
An expanding shockwave that reaches radius and fades. Its stroke
starts at 18% of the radius; use Juice::ring_width for large,
thin reach indicators.
Sourcepub fn ring_width(&mut self, at: Vec2, color: Color, radius: f32, width: f32)
pub fn ring_width(&mut self, at: Vec2, color: Color, radius: f32, width: f32)
An expanding ring whose stroke starts at width units and thins out,
for wide areas (a hearing radius, a blast zone) that should stay crisp.
use ferravex_render::{Color, juice::Juice, vec2};
let mut fx = Juice::new();
fx.ring_width(vec2(200., 200.), Color::new(1., 0.8, 0.3, 1.), 180., 3.);
assert_eq!(fx.counts().rings, 1);Sourcepub fn popup(&mut self, at: Vec2, text: &str, color: Color)
pub fn popup(&mut self, at: Vec2, text: &str, color: Color)
Short floating text (a number, a grade) that pops in at at, rises
and fades. Keep it to a few characters: “+25”, “x3”, “PERFECT”.
Sourcepub fn popup_icon(&mut self, at: Vec2, icon: Icon, text: &str, color: Color)
pub fn popup_icon(&mut self, at: Vec2, icon: Icon, text: &str, color: Color)
A floating icon with optional short text beside it, such as a coin and “+25” rising from the tile that earned it.
Sourcepub fn popup_sized(
&mut self,
at: Vec2,
icon: Option<Icon>,
text: &str,
color: Color,
size: f32,
)
pub fn popup_sized( &mut self, at: Vec2, icon: Option<Icon>, text: &str, color: Color, size: f32, )
A popup at an explicit text size (popups default to 18, callouts to
32), with an optional icon; small sizes suit crowded boards.
use ferravex_render::{Color, juice::Juice, vec2, icons::Icon};
let mut fx = Juice::new();
fx.popup_sized(vec2(50., 50.), Some(Icon::Bomb), "-4", Color::new(1., 0.4, 0.3, 1.), 12.);
assert_eq!(fx.counts().popups, 1);Sourcepub fn callout(&mut self, at: Vec2, text: &str, color: Color)
pub fn callout(&mut self, at: Vec2, text: &str, color: Color)
A large floating callout for rare, important moments.
Sourcepub fn toast(&mut self, icon: Option<Icon>, text: &str, color: Color)
pub fn toast(&mut self, icon: Option<Icon>, text: &str, color: Color)
Replace the current toast: a short line with an optional icon, shown
by Juice::draw_toast for about two and a half seconds.
Sourcepub fn shake(&mut self, trauma: f32)
pub fn shake(&mut self, trauma: f32)
Add camera trauma (0–1); shake grows with its square and decays.
Sourcepub fn flash(&mut self, color: Color)
pub fn flash(&mut self, color: Color)
Tint the whole area with color; its alpha is the starting strength.
Sourcepub fn vignette(&mut self, color: Color)
pub fn vignette(&mut self, color: Color)
Glow the edges of the area with color (damage, danger, alarms).
Sourcepub fn shake_offset(&self) -> Vec2
pub fn shake_offset(&self) -> Vec2
Camera offset (logical units) for the current shake; add it to the game camera and keep HUD chrome steady.
Sourcepub fn draw_flash(&self, area: Rect)
pub fn draw_flash(&self, area: Rect)
Draw the current flash and edge vignette over area.
Sourcepub fn draw_toast(&self, anchor: Vec2)
pub fn draw_toast(&self, anchor: Vec2)
Draw the current toast as a pill centered on anchor.