I'm coding a game for a group project and I've run into a problem with the sound coding. I've successfully gotten the game to play the sound and play it on loop, but when I'm asking the sound to stop playing, it will not. I am also not sure how to properly use the isPlaying() boolean method within if statements in order to regulate when the sound plays.
Here is the code that I have for starting it:
And here is the code that I have tried using to stop it:
I am not sure how to fix the second bit of code to get the sound to stop when the Game Over sequence happens.
public int soundplay = 1;
public GreenfootSound music = new GreenfootSound("NinjaTheme.wav");
public void act()
{
if (soundplay == 1 && !music.isPlaying())
{
music.playLoop();
soundplay = 0;
}
if (Greenfoot.mousePressed(this))
{
Greenfoot.setWorld(new InstructionsWorld());
}
} Start_Button start = new Start_Button();
if (player != null && isTouching(Player.class))
{
removeTouching(Player.class);
player1.score = 0;
start.music.stop();
Greenfoot.setWorld(new GameOverWorld());
}

