Struct Juice

Source
pub struct Juice { /* private fields */ }
Expand description

Bounded pool of presentation effects. See the module docs.

Implementations§

Source§

impl Juice

Source

pub fn new() -> Juice

A pool with the default capacities.

Source

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).

Source

pub fn set_motion(&mut self, motion: Motion)

Select full or reduced motion; reduced removes shake and drift.

Source

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);
Source

pub fn set_reduced_flash(&mut self, reduced: bool)

Keep flashes and vignettes faint for players who reduce flashing.

Source

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));
Source

pub fn clear(&mut self)

Remove every live effect (for example on restart).

Source

pub fn is_idle(&self) -> bool

True when nothing is visible and nothing is moving.

Source

pub fn counts(&self) -> JuiceCounts

Live effect counts.

Source

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.

Source

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);
Source

pub fn sparkle(&mut self, at: Vec2, color: Color)

A few twinkling four-point stars around at: rewards, selections, magic.

Source

pub fn confetti(&mut self, at: Vec2, count: u32)

A celebratory shower of multicolored paper from at.

Source

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.

Source

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);
Source

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”.

Source

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.

Source

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);
Source

pub fn callout(&mut self, at: Vec2, text: &str, color: Color)

A large floating callout for rare, important moments.

Source

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.

Source

pub fn shake(&mut self, trauma: f32)

Add camera trauma (0–1); shake grows with its square and decays.

Source

pub fn flash(&mut self, color: Color)

Tint the whole area with color; its alpha is the starting strength.

Source

pub fn vignette(&mut self, color: Color)

Glow the edges of the area with color (damage, danger, alarms).

Source

pub fn update(&mut self, dt: f32)

Advance every effect by dt seconds of presentation time.

Source

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.

Source

pub fn draw(&self)

Draw sparks, rings and popups in the current camera’s units.

Source

pub fn draw_flash(&self, area: Rect)

Draw the current flash and edge vignette over area.

Source

pub fn draw_toast(&self, anchor: Vec2)

Draw the current toast as a pill centered on anchor.

Trait Implementations§

Source§

impl Clone for Juice

Source§

fn clone(&self) -> Juice

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Juice

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Juice

Source§

fn default() -> Juice

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Juice

§

impl RefUnwindSafe for Juice

§

impl Send for Juice

§

impl Sync for Juice

§

impl Unpin for Juice

§

impl UnwindSafe for Juice

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.