Skip to content

Commit

Permalink
Fix music syncing on restart from pause menu
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Jul 29, 2024
1 parent 6bc82ae commit 7586143
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/screen/playing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::core::pause::Pause;
use crate::game::actor::player::player;
use crate::game::audio::music::start_music;
use crate::game::audio::music::stop_music;
use crate::game::audio::music::Beat;
use crate::game::ground::ground;
use crate::game::spotlight::spotlight_lamp_spawner;
use crate::game::stats::Stats;
Expand Down Expand Up @@ -48,11 +49,13 @@ fn enter_playing(
game_root: Res<GameRoot>,
ui_root: Res<UiRoot>,
mut stats: ResMut<Stats>,
mut beat: ResMut<Beat>,
) {
commands.spawn_with(fade_in);

// Reset stats.
// Reset resources.
*stats = default();
*beat = default();

// TODO: Character select screen.
// Spawn player.
Expand Down
9 changes: 1 addition & 8 deletions src/screen/playing/pause_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use pyri_state::extra::entity_scope::StateScope;
use pyri_state::prelude::*;

use crate::core::pause::Pause;
use crate::game::audio::music::MusicHandle;
use crate::screen::fade_out;
use crate::screen::playing::PlayingAssets;
use crate::screen::playing::PlayingMenu;
Expand Down Expand Up @@ -110,15 +109,9 @@ fn continue_button(mut entity: EntityWorldMut) {
fn restart_button(mut entity: EntityWorldMut) {
entity.add(widget::menu_button("Restart")).insert((
On::<Pointer<Click>>::run(
|mut commands: Commands,
audio: Res<Audio>,
assets: Res<PlayingAssets>,
music_handle: Res<MusicHandle>,
mut audio_instances: ResMut<Assets<AudioInstance>>| {
|mut commands: Commands, audio: Res<Audio>, assets: Res<PlayingAssets>| {
commands.spawn_with(fade_out(Screen::Playing));
audio.play(assets.sfx_restart.clone()).with_volume(0.7);
let music = r!(audio_instances.get_mut(&music_handle.0));
music.seek_to(0.0);
},
),
Style {
Expand Down

0 comments on commit 7586143

Please sign in to comment.