Skip to content

Commit fc886a6

Browse files
committed
Fix multiple audio bug when exiting gameplay
1 parent c342bad commit fc886a6

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

source/core/src/main/com/csse3200/game/GdxGame.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
public class GdxGame extends Game {
2525
private static final Logger logger = LoggerFactory.getLogger(GdxGame.class);
26+
public static int musicON = 0;
2627

2728
@Override
2829
public void create() {

source/core/src/main/com/csse3200/game/screens/MainMenuScreen.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,12 @@ private void registerAudioAssets() {
105105
}
106106

107107
private void playMenuMusic() {
108-
if (ServiceLocator.getAudioService() != null) {
109-
ServiceLocator.getAudioService().playMusic("menu_bgm", true);
108+
if (GdxGame.musicON == 0) {
109+
if (ServiceLocator.getAudioService() != null) {
110+
ServiceLocator.getAudioService().playMusic("menu_bgm", true);
111+
// Set the flag to indicate music is now on
112+
GdxGame.musicON = 1;
113+
}
110114
}
111115
}
112116

0 commit comments

Comments
 (0)