Skip to content

Commit

Permalink
fix footsteps
Browse files Browse the repository at this point in the history
  • Loading branch information
aratama committed Nov 17, 2024
1 parent fac015b commit 74ca2f8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/entity/witch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::wand::Wand;
use crate::wand_props::wand_to_props;
use bevy::prelude::*;
use bevy_aseprite_ultra::prelude::*;
use bevy_kira_audio::prelude::*;
use bevy_rapier2d::prelude::*;
use std::f32::consts::PI;
use uuid::Uuid;
Expand All @@ -24,9 +23,6 @@ pub const PLAYER_MOVE_FORCE: f32 = 50000.0;
#[derive(Default, Component, Reflect)]
pub struct WitchWandSprite;

#[derive(Default, Component, Reflect)]
pub struct Footsteps(pub Handle<AudioInstance>);

#[derive(Component)]
pub struct Witch;

Expand Down Expand Up @@ -172,15 +168,19 @@ fn update_animation(
for (parent, mut animation) in witch_animation_query.iter_mut() {
if let Ok((actor, mut state)) = witch_query.get_mut(**parent) {
if actor.move_direction.length() < 0.01 {
*state = ActorState(AnimationState::Idle);
if state.0 != AnimationState::Idle {
*state = ActorState(AnimationState::Idle);
}

if animation.tag != Some("idle".to_string()) {
// アニメーションを切り替えても現在のフレーム位置が巻き戻らない?
// https://github.com/Lommix/bevy_aseprite_ultra/issues/14
animation.play("idle", AnimationRepeat::Loop);
}
} else {
*state = ActorState(AnimationState::Walk);
if state.0 != AnimationState::Walk {
*state = ActorState(AnimationState::Walk);
}

if animation.tag != Some("run".to_string()) {
animation.play("run", AnimationRepeat::Loop);
Expand Down
4 changes: 3 additions & 1 deletion src/footsteps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::time::Duration;
pub struct WitchWandSprite;

#[derive(Default, Component, Reflect)]
pub struct Footsteps(Handle<AudioInstance>);
pub struct Footsteps(pub Handle<AudioInstance>);

fn update_volume(
mut witch_query: Query<(&ActorState, &mut Footsteps), Changed<ActorState>>,
Expand All @@ -22,6 +22,8 @@ fn update_volume(
AnimationState::Walk => 0.6,
};
instance.set_volume(volume, AudioTween::linear(Duration::from_millis(200)));
} else {
warn!("no audio instance found");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use crate::entity::magic_circle::spawn_magic_circle;
use crate::entity::magic_circle::MagicCircleDestination;
use crate::entity::stone_lantern::spawn_stone_lantern;
use crate::entity::witch::spawn_witch;
use crate::entity::witch::Footsteps;
use crate::entity::GameEntity;
use crate::footsteps::Footsteps;
use crate::hud::life_bar::LifeBarResource;
use crate::inventory_item::InventoryItem;
use crate::player_state::PlayerState;
Expand Down

0 comments on commit 74ca2f8

Please sign in to comment.