Skip to content

Commit

Permalink
Revert "Revert "Support running an animation N times (#19)""
Browse files Browse the repository at this point in the history
This reverts commit 87ac60b.
  • Loading branch information
djeedai committed Aug 4, 2022
1 parent 244ec9d commit 221d8bf
Show file tree
Hide file tree
Showing 11 changed files with 286 additions and 242 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Added `RepeatCount` and `RepeatStrategy` for more granular control over animation looping.
- Added `with_repeat_count()` and `with_repeat_strategy()` builder methods to `Tween<T>`.

## [0.5.0] - 2022-08-04

### Added
Expand All @@ -18,6 +25,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Compatible with Bevy 0.8
- Double boxing in `Sequence` and `Tracks` was fixed. As a result, any custom tweenables
should implement `From` for `BoxedTweenable` to make those APIs easier to use.
- Removed the `tweening_type` parameter from the signature of `Tween<T>::new()`; use `with_repeat_count()` and `with_repeat_strategy()` instead.

### Removed

- Removed `Tweenable::is_looping()`, which was not implemented for most tweenables.
- Removed `TweeningType` in favor of `RepeatCount` and `RepeatStrategy`.

## [0.4.0] - 2022-04-16

Expand Down
5 changes: 3 additions & 2 deletions examples/colormaterial_color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@ fn setup(

let tween = Tween::new(
*ease_function,
TweeningType::PingPong,
Duration::from_secs(1),
ColorMaterialColorLens {
start: Color::RED,
end: Color::BLUE,
},
);
)
.with_repeat_count(RepeatCount::Infinite)
.with_repeat_strategy(RepeatStrategy::MirroredRepeat);

commands
.spawn_bundle(MaterialMesh2dBundle {
Expand Down
1 change: 0 additions & 1 deletion examples/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
start_time_ms += 500;
let tween_scale = Tween::new(
EaseFunction::BounceOut,
TweeningType::Once,
Duration::from_secs(2),
TransformScaleLens {
start: Vec3::splat(0.01),
Expand Down
43 changes: 27 additions & 16 deletions examples/sequence.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::time::Duration;

use bevy::prelude::*;

use bevy_tweening::{lens::*, *};
use std::time::Duration;

fn main() {
App::default()
Expand Down Expand Up @@ -107,19 +109,31 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
Vec3::new(margin, screen_y - margin, 0.),
Vec3::new(margin, margin, 0.),
];
// Build a sequence from an iterator over a Tweenable (here, a Tween<Transform>)
// Build a sequence from an iterator over a Tweenable (here, a
// Tracks<Transform>)
let seq = Sequence::new(dests.windows(2).enumerate().map(|(index, pair)| {
Tween::new(
EaseFunction::QuadraticInOut,
TweeningType::Once,
Duration::from_secs(1),
TransformPositionLens {
start: pair[0] - center,
end: pair[1] - center,
},
)
// Get an event after each segment
.with_completed_event(index as u64)
Tracks::new([
Tween::new(
EaseFunction::QuadraticInOut,
Duration::from_millis(250),
TransformRotateZLens {
start: 0.,
end: 180_f32.to_radians(),
},
)
.with_repeat_count(RepeatCount::Finite(4))
.with_repeat_strategy(RepeatStrategy::MirroredRepeat),
Tween::new(
EaseFunction::QuadraticInOut,
Duration::from_secs(1),
TransformPositionLens {
start: pair[0] - center,
end: pair[1] - center,
},
)
// Get an event after each segment
.with_completed_event(index as u64),
])
}));

commands
Expand All @@ -138,7 +152,6 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
// scaling size at the same time.
let tween_move = Tween::new(
EaseFunction::QuadraticInOut,
TweeningType::Once,
Duration::from_secs(1),
TransformPositionLens {
start: Vec3::new(-200., 100., 0.),
Expand All @@ -148,7 +161,6 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
.with_completed_event(99); // Get an event once move completed
let tween_rotate = Tween::new(
EaseFunction::QuadraticInOut,
TweeningType::Once,
Duration::from_secs(1),
TransformRotationLens {
start: Quat::IDENTITY,
Expand All @@ -157,7 +169,6 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
);
let tween_scale = Tween::new(
EaseFunction::QuadraticInOut,
TweeningType::Once,
Duration::from_secs(1),
TransformScaleLens {
start: Vec3::ONE,
Expand Down
5 changes: 3 additions & 2 deletions examples/sprite_color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ fn setup(mut commands: Commands) {
] {
let tween = Tween::new(
*ease_function,
TweeningType::PingPong,
std::time::Duration::from_secs(1),
SpriteColorLens {
start: Color::RED,
end: Color::BLUE,
},
);
)
.with_repeat_count(RepeatCount::Infinite)
.with_repeat_strategy(RepeatStrategy::MirroredRepeat);

commands
.spawn_bundle(SpriteBundle {
Expand Down
5 changes: 3 additions & 2 deletions examples/text_color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
] {
let tween = Tween::new(
*ease_function,
TweeningType::PingPong,
std::time::Duration::from_secs(1),
TextColorLens {
start: Color::RED,
end: Color::BLUE,
section: 0,
},
);
)
.with_repeat_count(RepeatCount::Infinite)
.with_repeat_strategy(RepeatStrategy::MirroredRepeat);

commands
.spawn_bundle(TextBundle {
Expand Down
5 changes: 3 additions & 2 deletions examples/transform_rotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@ fn setup(mut commands: Commands) {
] {
let tween = Tween::new(
*ease_function,
TweeningType::PingPong,
std::time::Duration::from_secs(1),
TransformRotationLens {
start: Quat::IDENTITY,
end: Quat::from_axis_angle(Vec3::Z, std::f32::consts::PI / 2.),
},
);
)
.with_repeat_count(RepeatCount::Infinite)
.with_repeat_strategy(RepeatStrategy::MirroredRepeat);

commands
.spawn_bundle(SpatialBundle {
Expand Down
5 changes: 3 additions & 2 deletions examples/transform_translation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ fn setup(mut commands: Commands) {
] {
let tween = Tween::new(
*ease_function,
TweeningType::PingPong,
std::time::Duration::from_secs(1),
TransformPositionLens {
start: Vec3::new(x, screen_y, 0.),
end: Vec3::new(x, -screen_y, 0.),
},
);
)
.with_repeat_count(RepeatCount::Infinite)
.with_repeat_strategy(RepeatStrategy::MirroredRepeat);

commands
.spawn_bundle(SpriteBundle {
Expand Down
5 changes: 3 additions & 2 deletions examples/ui_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ fn setup(mut commands: Commands) {
] {
let tween = Tween::new(
*ease_function,
TweeningType::PingPong,
std::time::Duration::from_secs(1),
UiPositionLens {
start: UiRect {
Expand All @@ -92,7 +91,9 @@ fn setup(mut commands: Commands) {
bottom: Val::Auto,
},
},
);
)
.with_repeat_count(RepeatCount::Infinite)
.with_repeat_strategy(RepeatStrategy::MirroredRepeat);

commands
.spawn_bundle(NodeBundle {
Expand Down
Loading

0 comments on commit 221d8bf

Please sign in to comment.