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

2017/3/12

Song doesn't stop

ObliviaOng ObliviaOng

2017/3/12

#
'Sup, so I'm coding for a song to stop when an object is clicked but if the object hasn't been clicked yet the song would be played on loop and I know that the code should look like this
GreenfootSound song = new GreenfootSound("MusicScreen.mp3");
        if (Greenfoot.mouseClicked(this))
        {
            song.stop();
        }
        else
        {
            song.playLoop();
        }
but the thing is the song doesn't stop for some reason?
danpost danpost

2017/3/12

#
Provided the first line is placed properly in your code, the following should work:
if (Greenfoot.mouseClicked(this))
{
    if (song.isPlaying())
    {
        song.stop();
    }
    else
    {
        song.playLoop();
    }
}
ObliviaOng ObliviaOng

2017/3/14

#
I tried using the code that you gave but this time the song isn't playing at all
Super_Hippo Super_Hippo

2017/3/14

#
Your line 1 should be outside any methods and the code danpost provided should be in the act method.
You need to login to post a reply.