Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
components: rustfmt, clippy
- name: Install cargo-tarpaulin
run: |
RUST_BACKTRACE=1 cargo install --version 0.31.2 cargo-tarpaulin
RUST_BACKTRACE=1 cargo install --version 0.32.8 cargo-tarpaulin
- name: Generate code coverage
run: |
RUST_BACKTRACE=1 cargo tarpaulin --engine llvm --verbose --timeout 120 --out Lcov --workspace --all-features
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ bevy_text = ["bevy/bevy_text", "bevy/bevy_render", "bevy/bevy_sprite"]

[dependencies]
# Note: abuse 'bevy_color' to force 'bevy_math/curve' feature, which defines EaseFunction
bevy = { version = "0.18", default-features = false, features = [
bevy = { version = "0.19", default-features = false, features = [
"bevy_color",
"bevy_asset",
"bevy_log",
] }
thiserror = "2"

[dev-dependencies]
bevy-inspector-egui = { version = "0.36", default-features = false, features = [
bevy-inspector-egui = { version = "0.37", default-features = false, features = [
"bevy_render",
"bevy_pbr",
] }
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ criterion = { version = "0.5", features = ["html_reports"] }
bevy_tweening = { path = "../" }

[dependencies.bevy]
version = "0.18"
version = "0.19"
default-features = false
features = ["bevy_render", "bevy_sprite", "bevy_text", "bevy_ui"]

Expand Down
23 changes: 12 additions & 11 deletions examples/ambient_light.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
//! Example demonstrating resource animation and various transform shortcuts.
//!
//! The example animates the `AmbientLight` resource of Bevy's PBR renderer.
//! This is mostly for example purpose; you probably want to animate some other
//! (custom) resource. It also moves a capsule object back and forth with the
//! `move_to()` command extension, and make it "resonate" by quickly scaling it
//! between 100% and 110% size with the `scale_to()` command extension.
//! The example animates the `GlobalAmbientLight` resource of Bevy's PBR
//! renderer. This is mostly for example purpose; you probably want to animate
//! some other (custom) resource. It also moves a capsule object back and forth
//! with the `move_to()` command extension, and make it "resonate" by quickly
//! scaling it between 100% and 110% size with the `scale_to()` command
//! extension.

use std::{
f32::consts::{FRAC_PI_2, FRAC_PI_4},
time::Duration,
};

use bevy::{color::palettes::css::*, post_process::bloom::Bloom, prelude::*, render::view::Hdr};
use bevy::{camera::Hdr, color::palettes::css::*, post_process::bloom::Bloom, prelude::*};
use bevy_tweening::{lens::*, *};

mod utils;

// Define our own `Lens` to animate the `AmbientLight` resource.
// Define our own `Lens` to animate the `GlobalAmbientLight` resource.
struct AmbientLightBrightnessLens {
pub start: f32,
pub end: f32,
}

// Implement the `Lens` trait.
impl Lens<AmbientLight> for AmbientLightBrightnessLens {
fn lerp(&mut self, mut target: Mut<AmbientLight>, ratio: f32) {
impl Lens<GlobalAmbientLight> for AmbientLightBrightnessLens {
fn lerp(&mut self, mut target: Mut<GlobalAmbientLight>, ratio: f32) {
target.brightness = self.start.lerp(self.end, ratio);
}
}
Expand All @@ -50,7 +51,7 @@ fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
mut ambient_light: ResMut<AmbientLight>,
mut ambient_light: ResMut<GlobalAmbientLight>,
) -> Result<(), BevyError> {
// Some fancy 3D camera with HDR and bloom, to emphasize the change of ambient
// brightness.
Expand Down Expand Up @@ -97,7 +98,7 @@ fn setup(
.with_repeat(RepeatCount::Infinite, RepeatStrategy::MirroredRepeat);
commands.spawn((
TweenAnim::new(tween),
AnimTarget::resource::<AmbientLight>(),
AnimTarget::resource::<GlobalAmbientLight>(),
));

// Spawn some animated character-like capsule...
Expand Down
45 changes: 38 additions & 7 deletions examples/colormaterial_color.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
use std::time::Duration;

use bevy::{color::palettes::css::*, prelude::*};
use bevy_inspector_egui::{bevy_egui::EguiPlugin, prelude::*, quick::ResourceInspectorPlugin};
use bevy_tweening::{lens::*, *};

mod utils;

fn main() {
App::default()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "ColorMaterialColorLens".to_string(),
resolution: bevy::window::WindowResolution::new(1200, 600),
present_mode: bevy::window::PresentMode::Fifo, // vsync
.add_plugins((
DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "ColorMaterialColorLens".to_string(),
resolution: bevy::window::WindowResolution::new(1200, 600),
present_mode: bevy::window::PresentMode::Fifo, // vsync
..default()
}),
..default()
}),
..default()
}))
EguiPlugin::default(),
ResourceInspectorPlugin::<Options>::new(),
))
.init_resource::<Options>()
.register_type::<Options>()
.add_systems(Update, utils::close_on_esc)
.add_plugins(TweeningPlugin)
.add_systems(Startup, setup)
.add_systems(Update, update_animation_speed)
.run();
}

#[derive(Resource, Reflect, InspectorOptions)]
#[reflect(InspectorOptions)]
struct Options {
#[inspector(min = 0., max = 100.)]
speed: f64,
}

impl Default for Options {
fn default() -> Self {
Self { speed: 1. }
}
}

fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
Expand Down Expand Up @@ -105,3 +126,13 @@ fn setup(

Ok(())
}

fn update_animation_speed(options: Res<Options>, mut q_anims: Query<&mut TweenAnim>) {
if !options.is_changed() {
return;
}

for mut anim in &mut q_anims {
anim.speed = options.speed;
}
}
9 changes: 6 additions & 3 deletions examples/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,15 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
children![(
Text::new(text.to_string()),
TextFont {
font: font.clone(),
font_size: 48.0,
font: font.clone().into(),
font_size: 48.0.into(),
..default()
},
TextColor(TEXT_COLOR),
TextLayout::new_with_justify(Justify::Center),
TextLayout {
justify: Justify::Center,
..default()
},
)],
))
.id();
Expand Down
14 changes: 10 additions & 4 deletions examples/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) -> Result<()> {

let font = asset_server.load("fonts/FiraMono-Regular.ttf");
let text_font = TextFont {
font,
font_size: 50.0,
font: font.into(),
font_size: 50.0.into(),
..default()
};

Expand All @@ -57,7 +57,10 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) -> Result<()> {
commands
.spawn((
Text2d::default(),
TextLayout::new_with_justify(justify),
TextLayout {
justify,
..default()
},
Transform::from_translation(Vec3::new(0., 40., 0.)),
RedProgress,
))
Expand All @@ -79,7 +82,10 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) -> Result<()> {
commands
.spawn((
Text2d::default(),
TextLayout::new_with_justify(justify),
TextLayout {
justify,
..default()
},
Transform::from_translation(Vec3::new(0., -40., 0.)),
BlueProgress,
))
Expand Down
4 changes: 2 additions & 2 deletions examples/text_color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn((
Text::new(*ease_name),
TextFont {
font: font.clone(),
font_size: 24.0,
font: font.clone().into(),
font_size: 24.0.into(),
..default()
},
TextColor(Color::WHITE),
Expand Down
11 changes: 7 additions & 4 deletions src/lens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,10 @@ pub struct ColorMaterialColorLens {
#[cfg(feature = "bevy_sprite")]
impl Lens<ColorMaterial> for ColorMaterialColorLens {
fn lerp(&mut self, mut target: Mut<ColorMaterial>, ratio: f32) {
target.color = self.start.mix(&self.end, ratio);
let color = self.start.mix(&self.end, ratio);
if target.color != color {
target.color = color;
}
}
}

Expand Down Expand Up @@ -1150,7 +1153,7 @@ mod tests {
let mut added = Tick::new(0);
let mut last_changed = Tick::new(0);
let mut caller = MaybeLocation::caller();
let asset = assets.get_mut(handle.id()).unwrap();
let asset = assets.get_mut_untracked(handle.id()).unwrap();
let target = Mut::new(
asset,
&mut added,
Expand All @@ -1167,7 +1170,7 @@ mod tests {
let mut added = Tick::new(0);
let mut last_changed = Tick::new(0);
let mut caller = MaybeLocation::caller();
let asset = assets.get_mut(handle.id()).unwrap();
let asset = assets.get_mut_untracked(handle.id()).unwrap();
let target = Mut::new(
asset,
&mut added,
Expand All @@ -1184,7 +1187,7 @@ mod tests {
let mut added = Tick::new(0);
let mut last_changed = Tick::new(0);
let mut caller = MaybeLocation::caller();
let asset = assets.get_mut(handle.id()).unwrap();
let asset = assets.get_mut_untracked(handle.id()).unwrap();
let target = Mut::new(
asset,
&mut added,
Expand Down
Loading
Loading