So I looked around for a little while and I found out how to play music, but stopping the music seems to be a problem. I am trying to make it so that when I press space, the music will stop playing (used for a main menu where when space is pressed, the game starts) but the music just carries on. Is there anything wrong with my code or can anyone help me out with what to do here as anything I try just doesn't seem to work as the music carries on playing whenever space is pressed. Here is my code:
Anyone help? Thanks
GreenfootSound bgMusic = new GreenfootSound("mainmusic.mp3");
if(Greenfoot.isKeyDown("space"))
{
musicSpacePressed = 1;
bgMusic.stop();
}
if(!bgMusic.isPlaying())
{
if(musicSpacePressed != 1)
{
bgMusic.play();
}
}