diff options
author | Max-001 <maxsmits21@kpnmail.nl> | 2025-01-12 11:12:03 +0100 |
---|---|---|
committer | Max-001 <maxsmits21@kpnmail.nl> | 2025-01-12 11:12:03 +0100 |
commit | 629a4ec2fea616081bf116fea22b13cdd7e1a921 (patch) | |
tree | e364d2525218768d992b7bf811970a43258098f6 | |
parent | 6879f036aebe8f279411fa30f2d7ae1e0614308c (diff) |
Bug fix: Audio now stops when leaving PreviewScene
-rw-r--r-- | game/preview/PrevPlayerScript.cpp | 3 | ||||
-rw-r--r-- | game/preview/PrevPlayerSubScene.cpp | 3 |
2 files changed, 4 insertions, 2 deletions
diff --git a/game/preview/PrevPlayerScript.cpp b/game/preview/PrevPlayerScript.cpp index f5a770a..ae25dad 100644 --- a/game/preview/PrevPlayerScript.cpp +++ b/game/preview/PrevPlayerScript.cpp @@ -66,7 +66,8 @@ bool PrevPlayerScript::key_pressed(const KeyPressEvent & ev) { this->head->data.position_offset -= 10; break; case Keycode::P: - this->get_component<AudioSource>().active = true; + this->get_components_by_name<AudioSource>("background_music").front().get().active + = true; break; case Keycode::J: this->get_components_by_name<Transform>("camera").front().get().position.x diff --git a/game/preview/PrevPlayerSubScene.cpp b/game/preview/PrevPlayerSubScene.cpp index 2403551..074cfb4 100644 --- a/game/preview/PrevPlayerSubScene.cpp +++ b/game/preview/PrevPlayerSubScene.cpp @@ -79,7 +79,8 @@ PrevPlayerSubScene::PrevPlayerSubScene(Scene & scn) { player.add_component<BoxCollider>(vec2(40, 50)); player.add_component<BehaviorScript>().set_script<PrevPlayerScript>(); - AudioSource & audio = player.add_component<AudioSource>(Asset {"asset/music/level.ogg"}); + GameObject music = scn.new_object("background_music", "background_music"); + AudioSource & audio = music.add_component<AudioSource>(Asset {"asset/music/level.ogg"}); audio.loop = true; audio.play_on_awake = true; audio.active = false; |