I made a actor class for a music class where when you click on it, it turns off the music. However, if I leave the music on, go through menus and return back to the world where the actor class was, the music starts again over top of the music that's currently playing. The music also runs when the game isnt even running
private GreenfootSound backgroundMusic = new GreenfootSound("bubblegumkk.mp3"); private boolean isMuted; public Music() { backgroundMusic.playLoop(); } public void act() { { if(Greenfoot.mouseClicked(this)) { isMuted = !isMuted; updateState(); } } } private void updateState() { if(isMuted) { setImage("MusicOff.png"); backgroundMusic.pause(); } else { setImage("MusicOn.png"); backgroundMusic.play(); } } public void stopped() { backgroundMusic.setVolume(0); //change bg to what you declared the file as } public void started() { backgroundMusic.setVolume(30); //change bg to what you declared the file as }