Module juice

Source
Expand description

Presentation “juice”: bursts, sparkles, confetti, shockwave rings, floating popups, toasts, screen shake and flashes that make accepted events felt instead of described.

Juice is a bounded, allocation-free (after construction) effect pool advanced by presentation frame time. It never feeds back into simulation: request effects only from events your rules actually accepted (a hit that landed, an order that shipped), then call Juice::update once per rendered frame and draw it in the same camera space as the game.

Effects that cannot fit replace the oldest effect of the same kind, so a storm of events never grows memory. Motion::Reduced disables shake, keeps popups still and thins particles; Juice::set_reduced_flash keeps full-screen flashes and vignettes subtle.

use ferravex_render::{Color, juice::Juice, vec2, icons::Icon};
let mut fx = Juice::new();
let gold = Color::from_hex(0xf7b553);
fx.burst(vec2(200., 120.), gold, 24);
fx.ring(vec2(200., 120.), gold, 48.);
fx.popup_icon(vec2(200., 100.), Icon::Coin, "+25", gold);
fx.shake(0.4);
assert!(fx.counts().sparks > 0 && fx.counts().popups == 1);
for _ in 0..240 {
    fx.update(1. / 60.);
}
assert!(fx.is_idle());
assert_eq!(fx.shake_offset(), vec2(0., 0.));

Structs§

Juice
Bounded pool of presentation effects. See the module docs.
JuiceCounts
Live effect counts, for diagnostics and tests.

Constants§

DEFAULT_POPUPS
Default number of simultaneous floating popups.
DEFAULT_RINGS
Default number of simultaneous rings.
DEFAULT_SPARKS
Default number of simultaneous particles.
MAX_LABEL
Longest popup or toast text kept, in bytes (cut at a character boundary).

Functions§

bob
A vertical bob offset of amplitude units at hz, for floating pickups, markers and selected pieces.
pulse
A smooth 0–1 pulse at hz cycles per second, for idle “look at me” motion.