Skip to content

Commit

Permalink
Add fade out tween to smoke
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Jul 25, 2024
1 parent bf670eb commit f1bdcd1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ bevy_mod_picking = { version = "0.20", default-features = false, features = [
"backend_bevy_ui",
] }
bevy_state = "0.14"
bevy_tweening = "0.11"
interpolation = "0.3"
iyes_progress = "0.12"
lazy-regex = { version = "3", features = ["lite"] }
Expand Down
3 changes: 3 additions & 0 deletions src/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ pub mod offset;
pub mod transition;

use bevy::prelude::*;
use bevy_tweening::TweeningPlugin;

pub(super) fn plugin(app: &mut App) {
app.add_plugins(TweeningPlugin);

app.add_plugins((backup::plugin, offset::plugin, transition::plugin));
}
5 changes: 3 additions & 2 deletions src/game/actor/movement/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ fn record_movement_action(
mut action_query: Query<(&ActionState<MovementAction>, &mut MovementController)>,
) {
for (action, mut controller) in &mut action_query {
let input = cq!(action.axis_pair(&MovementAction::Move));
controller.0 = input.xy().clamp_length_max(1.0);
controller.0 += cq!(action.axis_pair(&MovementAction::Move))
.xy()
.clamp_length_max(1.0);
}
}

Expand Down
15 changes: 14 additions & 1 deletion src/game/actor/movement/smoke.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::time::Duration;

use avian2d::prelude::*;
use bevy::ecs::system::EntityCommand;
use bevy::prelude::*;
use bevy_tweening::*;

use crate::core::UpdateSet;
use crate::game::actor::movement::MovementController;
Expand Down Expand Up @@ -33,6 +36,8 @@ fn spawn_movement_smoke(
}
}

const LIFETIME_SECS: f32 = 0.5;

fn smoke(movement: Vec2) -> impl EntityCommand<World> {
move |mut entity: EntityWorldMut| {
let parent = entity.world().resource::<GameRoot>().vfx;
Expand Down Expand Up @@ -71,9 +76,17 @@ fn smoke(movement: Vec2) -> impl EntityCommand<World> {
texture,
..default()
},
Animator::new(Tween::new(
EaseMethod::Linear,
Duration::from_secs_f32(LIFETIME_SECS),
lens::SpriteColorLens {
start: Color::WHITE,
end: Color::NONE,
},
)),
RigidBody::Kinematic,
LinearVelocity(-12.0 * movement),
DespawnOnTimer(Timer::from_seconds(0.2, TimerMode::Once)),
DespawnOnTimer(Timer::from_seconds(LIFETIME_SECS, TimerMode::Once)),
))
.set_parent(parent);
}
Expand Down

0 comments on commit f1bdcd1

Please sign in to comment.