Skip to content

Commit 7e3fbd9

Browse files
djeedaiazarmadr
authored andcommitted
Upgrade to Bevy 0.8
Upgrade to the latest released version 0.8.0 of Bevy. Add a new `bevy_asset` feature to enable animation of Bevy assets (types implementing the `Asset` trait). Bevy 0.8 does not contain `bevy_asset` in its defaul features, so this new feature reflects that new possibility to build Bevy and � Bevy Tweening without support for the `bevy_asset` crate. The new feature is enabled by default for discoverability and to prevent a behavior breaking change.
1 parent 531c116 commit 7e3fbd9

File tree

16 files changed

+188
-158
lines changed

16 files changed

+188
-158
lines changed

CHANGELOG.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
### Added
99

10-
- Add `is_forward()` and `is_backward()` convenience helpers to `TweeningDirection`.
11-
- Add `Tween::set_direction()` and `Tween::with_direction()` which allow configuring the playback direction of a tween, allowing to play it backward from end to start.
12-
- Support dynamically changing an animation's speed with `Animator::set_speed`
13-
- Add `AnimationSystem` label to tweening tick systems
14-
- A `BoxedTweenable` type to make working with `Box<dyn Tweenable + ...>` easier
10+
- Added `is_forward()` and `is_backward()` convenience helpers to `TweeningDirection`.
11+
- Added `Tween::set_direction()` and `Tween::with_direction()` which allow configuring the playback direction of a tween, allowing to play it backward from end to start.
12+
- Added support for dynamically changing an animation's speed with `Animator::set_speed`.
13+
- Added `AnimationSystem` label to tweening tick systems.
14+
- Added a `BoxedTweenable` trait to make working with `Box<dyn Tweenable + ...>` easier.
1515

1616
### Changed
1717

18+
- Compatible with Bevy 0.8
1819
- Double boxing in `Sequence` and `Tracks` was fixed. As a result, any custom tweenables
1920
should implement `From` for `BoxedTweenable` to make those APIs easier to use.
2021

Cargo.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bevy_tweening"
3-
version = "0.4.0"
3+
version = "0.5.0-dev"
44
authors = ["François Mockers <[email protected]>", "Jerome Humbert <[email protected]>"]
55
edition = "2021"
66
description = "Tweening animation plugin for the Bevy game engine"
@@ -13,26 +13,28 @@ readme = "README.md"
1313
exclude = ["examples/*.gif", ".github", "release.md"]
1414

1515
[features]
16-
default = ["bevy_sprite", "bevy_ui"]
16+
default = ["bevy_sprite", "bevy_ui", "bevy_asset"]
17+
# Enable support for Asset animation
18+
bevy_asset = ["bevy/bevy_asset"]
1719
# Enable built-in lenses for Bevy sprites
1820
bevy_sprite = ["bevy/bevy_sprite", "bevy/bevy_render"]
1921
# Enable built-in lenses for Bevy UI
2022
bevy_ui = ["bevy/bevy_ui", "bevy/bevy_text", "bevy/bevy_render"]
2123

2224
[dependencies]
2325
interpolation = "0.2"
24-
bevy = { version = "0.7", default-features = false }
26+
bevy = { version = "0.8", default-features = false }
2527

2628
[dev-dependencies]
27-
bevy-inspector-egui = "0.10"
29+
bevy-inspector-egui = "0.12"
2830

2931
[[example]]
3032
name = "menu"
3133
required-features = [ "bevy/bevy_winit" ]
3234

3335
[[example]]
3436
name = "colormaterial_color"
35-
required-features = [ "bevy_sprite", "bevy/bevy_winit" ]
37+
required-features = [ "bevy_asset", "bevy_sprite", "bevy/bevy_winit" ]
3638

3739
[[example]]
3840
name = "sprite_color"

README.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![Crate](https://img.shields.io/crates/v/bevy_tweening.svg)](https://crates.io/crates/bevy_tweening)
66
[![Build Status](https://github.com/djeedai/bevy_tweening/actions/workflows/ci.yaml/badge.svg)](https://github.com/djeedai/bevy_tweening/actions/workflows/ci.yaml)
77
[![Coverage Status](https://coveralls.io/repos/github/djeedai/bevy_tweening/badge.svg?branch=main&kill_cache=1)](https://coveralls.io/github/djeedai/bevy_tweening?branch=main)
8-
[![Bevy tracking](https://img.shields.io/badge/Bevy%20tracking-v0.7-lightblue)](https://github.com/bevyengine/bevy/blob/main/docs/plugins_guidelines.md#main-branch-tracking)
8+
[![Bevy tracking](https://img.shields.io/badge/Bevy%20tracking-v0.8-lightblue)](https://github.com/bevyengine/bevy/blob/main/docs/plugins_guidelines.md#main-branch-tracking)
99

1010
Tweening animation plugin for the Bevy game engine.
1111

@@ -31,6 +31,7 @@ This crate supports the following features:
3131

3232
| Feature | Default | Description |
3333
|---|---|---|
34+
| `bevy_asset` | Yes | Enable animating Bevy assets (`Asset`) in addition of components. |
3435
| `bevy_sprite` | Yes | Includes built-in lenses for some `Sprite`-related components. |
3536
| `bevy_ui` | Yes | Includes built-in lenses for some UI-related components. |
3637

@@ -63,7 +64,7 @@ let tween = Tween::new(
6364
// to animate it. It also contains the start and end values associated
6465
// with the animation ratios 0. and 1.
6566
TransformPositionLens {
66-
start: Vec3::new(0., 0., 0.),
67+
start: Vec3::ZERO,
6768
end: Vec3::new(1., 2., -4.),
6869
},
6970
);
@@ -111,16 +112,16 @@ The naming scheme for predefined lenses is `"<TargetName><FieldName>Lens"`, wher
111112

112113
| Target Component | Animated Field | Lens | Feature |
113114
|---|---|---|---|
114-
| [`Transform`](https://docs.rs/bevy/0.7.0/bevy/transform/components/struct.Transform.html) | [`translation`](https://docs.rs/bevy/0.7.0/bevy/transform/components/struct.Transform.html#structfield.translation) | [`TransformPositionLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.TransformPositionLens.html) | |
115-
| | [`rotation`](https://docs.rs/bevy/0.7.0/bevy/transform/components/struct.Transform.html#structfield.rotation) (`Quat`| [`TransformRotationLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.TransformRotationLens.html) | |
116-
| | [`rotation`](https://docs.rs/bevy/0.7.0/bevy/transform/components/struct.Transform.html#structfield.rotation) (angle)² | [`TransformRotateXLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.TransformRotateXLens.html) | |
117-
| | [`rotation`](https://docs.rs/bevy/0.7.0/bevy/transform/components/struct.Transform.html#structfield.rotation) (angle)² | [`TransformRotateYLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.TransformRotateYLens.html) | |
118-
| | [`rotation`](https://docs.rs/bevy/0.7.0/bevy/transform/components/struct.Transform.html#structfield.rotation) (angle)² | [`TransformRotateZLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.TransformRotateZLens.html) | |
119-
| | [`rotation`](https://docs.rs/bevy/0.7.0/bevy/transform/components/struct.Transform.html#structfield.rotation) (angle)² | [`TransformRotateAxisLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.TransformRotateAxisLens.html) | |
120-
| | [`scale`](https://docs.rs/bevy/0.7.0/bevy/transform/components/struct.Transform.html#structfield.scale) | [`TransformScaleLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.TransformScaleLens.html) | |
121-
| [`Sprite`](https://docs.rs/bevy/0.7.0/bevy/sprite/struct.Sprite.html) | [`color`](https://docs.rs/bevy/0.7.0/bevy/sprite/struct.Sprite.html#structfield.color) | [`SpriteColorLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.SpriteColorLens.html) | `bevy_sprite` |
122-
| [`Style`](https://docs.rs/bevy/0.7.0/bevy/ui/struct.Style.html) | [`position`](https://docs.rs/bevy/0.7.0/bevy/ui/struct.Style.html#structfield.position) | [`UiPositionLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.UiPositionLens.html) | `bevy_ui` |
123-
| [`Text`](https://docs.rs/bevy/0.7.0/bevy/text/struct.Text.html) | [`TextStyle::color`](https://docs.rs/bevy/0.7.0/bevy/text/struct.TextStyle.html#structfield.color) | [`TextColorLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.TextColorLens.html) | `bevy_ui` |
115+
| [`Transform`](https://docs.rs/bevy/0.8.0/bevy/transform/components/struct.Transform.html) | [`translation`](https://docs.rs/bevy/0.8.0/bevy/transform/components/struct.Transform.html#structfield.translation) | [`TransformPositionLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.TransformPositionLens.html) | |
116+
| | [`rotation`](https://docs.rs/bevy/0.8.0/bevy/transform/components/struct.Transform.html#structfield.rotation) (`Quat`| [`TransformRotationLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.TransformRotationLens.html) | |
117+
| | [`rotation`](https://docs.rs/bevy/0.8.0/bevy/transform/components/struct.Transform.html#structfield.rotation) (angle)² | [`TransformRotateXLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.TransformRotateXLens.html) | |
118+
| | [`rotation`](https://docs.rs/bevy/0.8.0/bevy/transform/components/struct.Transform.html#structfield.rotation) (angle)² | [`TransformRotateYLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.TransformRotateYLens.html) | |
119+
| | [`rotation`](https://docs.rs/bevy/0.8.0/bevy/transform/components/struct.Transform.html#structfield.rotation) (angle)² | [`TransformRotateZLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.TransformRotateZLens.html) | |
120+
| | [`rotation`](https://docs.rs/bevy/0.8.0/bevy/transform/components/struct.Transform.html#structfield.rotation) (angle)² | [`TransformRotateAxisLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.TransformRotateAxisLens.html) | |
121+
| | [`scale`](https://docs.rs/bevy/0.8.0/bevy/transform/components/struct.Transform.html#structfield.scale) | [`TransformScaleLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.TransformScaleLens.html) | |
122+
| [`Sprite`](https://docs.rs/bevy/0.8.0/bevy/sprite/struct.Sprite.html) | [`color`](https://docs.rs/bevy/0.8.0/bevy/sprite/struct.Sprite.html#structfield.color) | [`SpriteColorLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.SpriteColorLens.html) | `bevy_sprite` |
123+
| [`Style`](https://docs.rs/bevy/0.8.0/bevy/ui/struct.Style.html) | [`position`](https://docs.rs/bevy/0.8.0/bevy/ui/struct.Style.html#structfield.position) | [`UiPositionLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.UiPositionLens.html) | `bevy_ui` |
124+
| [`Text`](https://docs.rs/bevy/0.8.0/bevy/text/struct.Text.html) | [`TextStyle::color`](https://docs.rs/bevy/0.8.0/bevy/text/struct.TextStyle.html#structfield.color) | [`TextColorLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.TextColorLens.html) | `bevy_ui` |
124125

125126
¹ Shortest-path interpolation between two rotations, using `Quat::slerp()`.
126127

@@ -130,9 +131,11 @@ See the [comparison of rotation lenses](https://docs.rs/bevy_tweening/0.4.0/bevy
130131

131132
### Bevy Assets
132133

134+
Asset animation always requires the `bevy_asset` feature.
135+
133136
| Target Asset | Animated Field | Lens | Feature |
134137
|---|---|---|---|
135-
| [`ColorMaterial`](https://docs.rs/bevy/0.7.0/bevy/sprite/struct.ColorMaterial.html) | [`color`](https://docs.rs/bevy/0.7.0/bevy/sprite/struct.ColorMaterial.html#structfield.color) | [`ColorMaterialColorLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.ColorMaterialColorLens.html) | `bevy_sprite` |
138+
| [`ColorMaterial`](https://docs.rs/bevy/0.8.0/bevy/sprite/struct.ColorMaterial.html) | [`color`](https://docs.rs/bevy/0.8.0/bevy/sprite/struct.ColorMaterial.html#structfield.color) | [`ColorMaterialColorLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.ColorMaterialColorLens.html) | `bevy_asset` + `bevy_sprite` |
136139

137140
## Custom lens
138141

@@ -186,7 +189,7 @@ Then, in addition, the system `component_animator_system::<CustomComponent>` nee
186189

187190
## Custom asset support
188191

189-
The process is similar to custom components, creating a custom lens for the custom asset. The system to add is `asset_animator_system::<CustomAsset>`.
192+
The process is similar to custom components, creating a custom lens for the custom asset. The system to add is `asset_animator_system::<CustomAsset>`. This requires the `bevy_asset` feature (enabled by default).
190193

191194
## Examples
192195

benchmarks/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ criterion = { version = "0.3", features = ["html_reports"] }
1818
bevy_tweening = { path = "../" }
1919

2020
[dependencies.bevy]
21-
version = "0.6"
21+
version = "0.8.0"
2222
default-features = false
2323
features = [ "render" ]
2424

benchmarks/benches/lens.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ fn text_color_lens(c: &mut Criterion) {
1111
end: Color::BLUE,
1212
section: 0,
1313
};
14-
let mut text = Text::with_section(
14+
let mut text = Text::from_section(
1515
"test".to_string(),
1616
TextStyle {
1717
font: Default::default(),
1818
font_size: 60.0,
1919
color: Color::WHITE,
2020
},
21-
TextAlignment {
22-
vertical: VerticalAlign::Center,
23-
horizontal: HorizontalAlign::Center,
24-
},
25-
);
21+
)
22+
.with_alignment(TextAlignment {
23+
vertical: VerticalAlign::Center,
24+
horizontal: HorizontalAlign::Center,
25+
});
2626
c.bench_function("TextColorLens", |b| {
2727
b.iter(|| lens.lerp(&mut text, black_box(0.3)))
2828
});

examples/colormaterial_color.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn setup(
2525
mut meshes: ResMut<Assets<Mesh>>,
2626
mut materials: ResMut<Assets<ColorMaterial>>,
2727
) {
28-
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
28+
commands.spawn_bundle(Camera2dBundle::default());
2929

3030
let size = 80.;
3131

examples/menu.rs

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ fn main() {
2020
}
2121

2222
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
23-
commands.spawn_bundle(UiCameraBundle::default());
23+
commands.spawn_bundle(Camera2dBundle::default());
2424

2525
let font = asset_server.load("fonts/FiraMono-Regular.ttf");
2626

27-
let container = commands
27+
commands
2828
.spawn_bundle(NodeBundle {
2929
style: Style {
3030
position_type: PositionType::Absolute,
31-
position: Rect::all(Val::Px(0.)),
32-
margin: Rect::all(Val::Px(16.)),
33-
padding: Rect::all(Val::Px(16.)),
31+
position: UiRect::all(Val::Px(0.)),
32+
margin: UiRect::all(Val::Px(16.)),
33+
padding: UiRect::all(Val::Px(16.)),
3434
flex_direction: FlexDirection::ColumnReverse,
3535
align_content: AlignContent::Center,
3636
align_items: AlignItems::Center,
@@ -42,60 +42,59 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
4242
..default()
4343
})
4444
.insert(Name::new("menu"))
45-
.id();
46-
47-
let mut start_time_ms = 0;
48-
for text in &["Continue", "New Game", "Settings", "Quit"] {
49-
let delay = Delay::new(Duration::from_millis(start_time_ms));
50-
start_time_ms += 500;
51-
let tween_scale = Tween::new(
52-
EaseFunction::BounceOut,
53-
TweeningType::Once,
54-
Duration::from_secs(2),
55-
TransformScaleLens {
56-
start: Vec3::splat(0.01),
57-
end: Vec3::ONE,
58-
},
59-
);
60-
let seq = delay.then(tween_scale);
61-
commands
62-
.spawn_bundle(NodeBundle {
63-
node: Node {
64-
size: Vec2::new(300., 80.),
65-
},
66-
style: Style {
67-
min_size: Size::new(Val::Px(300.), Val::Px(80.)),
68-
margin: Rect::all(Val::Px(8.)),
69-
padding: Rect::all(Val::Px(8.)),
70-
align_content: AlignContent::Center,
71-
align_items: AlignItems::Center,
72-
align_self: AlignSelf::Center,
73-
justify_content: JustifyContent::Center,
74-
..default()
75-
},
76-
color: UiColor(Color::rgb_u8(162, 226, 95)),
77-
transform: Transform::from_scale(Vec3::splat(0.01)),
78-
..default()
79-
})
80-
.insert(Name::new(format!("button:{}", text)))
81-
.insert(Parent(container))
82-
.insert(Animator::new(seq))
83-
.with_children(|parent| {
84-
parent.spawn_bundle(TextBundle {
85-
text: Text::with_section(
86-
text.to_string(),
87-
TextStyle {
88-
font: font.clone(),
89-
font_size: 48.0,
90-
color: Color::rgb_u8(83, 163, 130),
45+
.with_children(|container| {
46+
let mut start_time_ms = 0;
47+
for text in &["Continue", "New Game", "Settings", "Quit"] {
48+
let delay = Delay::new(Duration::from_millis(start_time_ms));
49+
start_time_ms += 500;
50+
let tween_scale = Tween::new(
51+
EaseFunction::BounceOut,
52+
TweeningType::Once,
53+
Duration::from_secs(2),
54+
TransformScaleLens {
55+
start: Vec3::splat(0.01),
56+
end: Vec3::ONE,
57+
},
58+
);
59+
let seq = delay.then(tween_scale);
60+
container
61+
.spawn_bundle(NodeBundle {
62+
node: Node {
63+
size: Vec2::new(300., 80.),
9164
},
92-
TextAlignment {
93-
vertical: VerticalAlign::Center,
94-
horizontal: HorizontalAlign::Center,
65+
style: Style {
66+
min_size: Size::new(Val::Px(300.), Val::Px(80.)),
67+
margin: UiRect::all(Val::Px(8.)),
68+
padding: UiRect::all(Val::Px(8.)),
69+
align_content: AlignContent::Center,
70+
align_items: AlignItems::Center,
71+
align_self: AlignSelf::Center,
72+
justify_content: JustifyContent::Center,
73+
..default()
9574
},
96-
),
97-
..default()
98-
});
99-
});
100-
}
75+
color: UiColor(Color::rgb_u8(162, 226, 95)),
76+
transform: Transform::from_scale(Vec3::splat(0.01)),
77+
..default()
78+
})
79+
.insert(Name::new(format!("button:{}", text)))
80+
.insert(Animator::new(seq))
81+
.with_children(|parent| {
82+
parent.spawn_bundle(TextBundle {
83+
text: Text::from_section(
84+
text.to_string(),
85+
TextStyle {
86+
font: font.clone(),
87+
font_size: 48.0,
88+
color: Color::rgb_u8(83, 163, 130),
89+
},
90+
)
91+
.with_alignment(TextAlignment {
92+
vertical: VerticalAlign::Center,
93+
horizontal: HorizontalAlign::Center,
94+
}),
95+
..default()
96+
});
97+
});
98+
}
99+
});
101100
}

examples/sequence.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct RedSprite;
3131
struct BlueSprite;
3232

3333
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
34-
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
34+
commands.spawn_bundle(Camera2dBundle::default());
3535

3636
let font = asset_server.load("fonts/FiraMono-Regular.ttf");
3737
let text_style_red = TextStyle {

examples/sprite_color.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main() {
1717
}
1818

1919
fn setup(mut commands: Commands) {
20-
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
20+
commands.spawn_bundle(Camera2dBundle::default());
2121

2222
let size = 80.;
2323

examples/text_color.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn main() {
2020
}
2121

2222
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
23-
commands.spawn_bundle(UiCameraBundle::default());
23+
commands.spawn_bundle(Camera2dBundle::default());
2424

2525
let font = asset_server.load("fonts/FiraMono-Regular.ttf");
2626

@@ -81,7 +81,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
8181
.spawn_bundle(TextBundle {
8282
style: Style {
8383
size: Size::new(Val::Px(size_x), Val::Px(size_y)),
84-
position: Rect {
84+
position: UiRect {
8585
left: Val::Px(x),
8686
top: Val::Px(y),
8787
right: Val::Auto,
@@ -94,15 +94,13 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
9494
justify_content: JustifyContent::Center,
9595
..default()
9696
},
97-
text: Text::with_section(
97+
text: Text::from_section(
9898
*ease_name,
9999
TextStyle {
100100
font: font.clone(),
101101
font_size: 24.0,
102102
color: Color::WHITE,
103103
},
104-
// you can still use Default
105-
default(),
106104
),
107105
..default()
108106
})

0 commit comments

Comments
 (0)