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

2015/3/22

How to Stop and reset bg Music

NoobCoder NoobCoder

2015/3/22

#
public class Gameover extends Actor
{
    GreenfootSound myMusic = new GreenfootSound("Hype.mp3");
    public void act() 
    {
        if (myMusic.isPlaying(true)) {
         myMusic.stop();
        } // Add your action code here.
    }    
}
Hi my game has music running in the background. when my character dies and its game over I want the music to stop, then start again when i click the play again button i created. I wrote this code in the Gameover class which is an image that is displayed in the background of the world saying game over. The main music code is written in my world background, so in my gameover class I wrote that if music playing is true then stop music but it doesn't work. Can somebody help thank you..
Super_Hippo Super_Hippo

2015/3/22

#
The GreenfootSound 'myMusic' in your Gameover class is not the same as in your world class. Instead, you create a new sound object (line 3). You could handle everything related to the sound in the world class.
NoobCoder NoobCoder

2015/3/22

#
Oh ok thank you for your help, i manage to do that ^^
You need to login to post a reply.