Skip to main content

Module tween

Module tween 

Source
Expand description

Display-independent tweens, easing, sequences, parallel groups and screen shake.

Tweens are plain game-owned values advanced by explicitly supplied time, like crate::time::Timer and crate::sprite::AnimationPlayer. Timing uses integer nanoseconds, so loops never drift and even Duration::MAX steps run in constant time. Nothing allocates while advancing; a Tween is Copy whenever its value is, and groups reuse the storage they were built with.

use rayengine_core::{events::Events, glam::Vec2, tween::*};
use std::time::Duration;

const PANEL: TweenId = TweenId(1);
let mut slide = Tween::new(Vec2::new(-200.0, 20.0), Vec2::new(16.0, 20.0), Duration::from_millis(400))
    .with_ease(Ease::BackOut)
    .with_delay(Duration::from_millis(100))
    .with_id(PANEL);
let mut completed = Events::with_capacity(4);
for _ in 0..60 {
    if let Some(done) = slide.advance(Duration::from_secs_f32(1.0 / 120.0)) {
        completed.send(done);
    }
}
assert_eq!(slide.value(), Vec2::new(16.0, 20.0)); // exact end value
assert_eq!(completed.read(), &[TweenCompleted { id: PANEL }]); // reported once

Re-exports§

pub use ease::Ease;

Modules§

ease
Standard easing curves as pure functions of normalized progress.

Structs§

Parallel
Runs members simultaneously and completes when every member is done.
Sequence
Runs members one after another. Time left over when a member completes carries into the next, so frame/tick partitioning never shifts later members.
Shake
Trauma-driven camera shake with smooth, seeded, deterministic noise.
ShakeConfig
Shake limits at full trauma. Offsets are in camera-aligned world units, so scale them to the camera’s visible height or distance.
ShakeError
A shake configuration with a nonfinite or out-of-range field.
ShakeSample
Displacement to apply to a camera this frame.
Tween
Typed interpolation between two values with duration, delay, easing and repetition.
TweenCompleted
Returned exactly once when a tween, sequence or group completes. Send it to a game-owned crate::events::Events queue.
TweenId
Game-defined tween identity carried by TweenCompleted, like input actions.

Enums§

TweenMode
Behavior after one traversal of a tween’s duration.

Traits§

Animate
Something that can be advanced inside a Sequence or Parallel group.
Tracks
Fixed-size storage of group members, indexed without allocation.
Tweenable
Values that can be interpolated by a tween.