This site requires JavaScript, please enable it in your browser!
Greenfoot back
BobBanana
BobBanana wrote ...

2017/3/23

Need help stopping music

BobBanana BobBanana

2017/3/23

#
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:
        GreenfootSound bgMusic = new GreenfootSound("mainmusic.mp3");  

        if(Greenfoot.isKeyDown("space"))
        {
            musicSpacePressed = 1;
            bgMusic.stop();
        }      
        if(!bgMusic.isPlaying())
        {
           if(musicSpacePressed != 1)
           {
               bgMusic.play();
           }
        }
Anyone help? Thanks
danpost danpost

2017/3/23

#
Is the first line inside or outside the method? Where is the code given located and what code starts the game and where is it located?
You need to login to post a reply.