be_tween/lib.rs
1#![allow(clippy::type_complexity)]
2//! Be-Tween
3//!
4//! Provides tweening values over time.
5
6//! These examples run with Bevy:
7//! ```no_run
8//! use bevy::prelude::*;
9//! use be_tween::*;
10//!
11//! App::default()
12//! .add_plugins(DefaultPlugins)
13//! // Add the plugin - NoEvent means that no custom events will be used
14//! .add_plugins(TweenPlugin)
15//! .run();
16//! ```
17//!
18//! Animate the position ([`Transform::translation`]) of an [`Entity`]:
19//! ```
20//! # use bevy::prelude::*;
21//! # use be_tween::*;
22//! # use std::time::Duration;
23//! # fn system(mut commands: Commands) {
24//! // Create a single animation (tween) to move an entity.
25//! let tween = Tween::new(
26//! // Animation time.
27//! Duration::from_secs(1),
28//! // Use a quadratic easing on both endpoints.
29//! EaseFunction::QuadraticInOut,
30//! // What we want to tween - the translation part of a transform
31//! TweenTranslation {
32//! start: Vec3::ZERO,
33//! end: Vec3::X,
34//! },
35//! );
36//!
37//! commands.spawn((
38//! // Spawn an entity to animate the position of.
39//! Transform::default(),
40//! // Add an Animator component to control and execute the animation.
41//! PlayTween::new(tween),
42//! ));
43//! # }
44//! ```
45//! A more elaborate example:
46//! ```
47//! # use bevy::prelude::*;
48//! # use be_tween::*;
49//! # use std::time::Duration;
50//! # fn system(mut commands: Commands) {
51//! let tween_translation = Tween::sequence([
52//! // First move to Vec3::X
53//! Tween::new(
54//! Duration::from_secs(1),
55//! EaseFunction::QuadraticInOut,
56//! TweenTranslation {
57//! start: Vec3::ZERO,
58//! end: Vec3::X,
59//! }),
60//! // Then move from Vec3::X to Vec3::Y 12 times
61//! Tween::repeat(
62//! RepeatTimes::N(12),
63//! Tween::new(
64//! Duration::from_secs(1),
65//! EaseFunction::QuadraticInOut,
66//! TweenTranslation {
67//! start: Vec3::X,
68//! end: Vec3::Y,
69//! })),
70//! // Then move up and down forever
71//! Tween::repeat(
72//! RepeatTimes::Infinite,
73//! Tween::sequence([
74//! Tween::new(
75//! Duration::from_secs(1),
76//! EaseFunction::QuadraticInOut,
77//! TweenTranslation {
78//! start: Vec3::Y,
79//! end: -Vec3::Y,
80//! }),
81//! Tween::new(
82//! Duration::from_secs(1),
83//! EaseFunction::QuadraticInOut,
84//! TweenTranslation {
85//! start: -Vec3::Y,
86//! end: Vec3::Y,
87//! }),
88//! ]))
89//! ]);
90//! let tween_color = Tween::sequence([Tween::new(
91//! Duration::from_secs(1),
92//! EaseFunction::QuadraticInOut,
93//! TweenSpriteColor {
94//! start: LinearRgba::WHITE.into(),
95//! end: LinearRgba::RED.into()
96//! })]
97//! );
98//!
99//! commands.spawn((
100//! // Spawn an entity to animate the position of.
101//! Transform::default(),
102//! // Now play the tweens
103//! PlayTween::new(tween_translation),
104//! // Note that both will be played in parallel!
105//! PlayTween::new(tween_color),
106//! ));
107//! # }
108//! ```
109
110#[cfg(feature = "bevy")]
111mod plugin;
112mod tween;
113
114#[cfg(feature = "bevy")]
115pub use plugin::*;
116pub use tween::*;