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

2015/7/29

How do I stop the background music?! (-.-')

PikachuKirby PikachuKirby

2015/7/29

#
When I stop my project, the Background Music keeps playing!! An error code came up saying 'cannot find symbol- method pause()'. Please help me!!
danpost danpost

2015/7/29

#
You need to show how you create/start the sound and how you are trying to stop it (what code are you using for all aspects of this particular sound). It is always better to show any and all declarations and methods concerning the issue. Read the page linked to 'Posting code? read this!' below the reply box before posting your code.
PikachuKirby PikachuKirby

2015/7/30

#
 public GameplayScreen()
    {
        super(800, 550, 1);
        GreenfootSound backgroundMusic = new GreenfootSound("Kirby Mass Attack Invincibility (Kirby Dance Remix).mp3");
        backgroundMusic.playLoop();
        prepare();
    }
    public void stopped()
    {
     ("Kirby Mass Attack Invincibility (Kirby Dance Remix).mp3").pause();
    }
 
   public void started()
   {
    ("Kirby Mass Attack Invincibility (Kirby Dance Remix).mp3").playLoop();
   }
danpost danpost

2015/7/30

#
Your reference to the GreenfootSound object is created inside the constructor of the class and is lost as soon as the constructor finishes executing. At that point, there is no way to refer to it, to do any actions on it (pause, stop, restart, or whatever -- the methods of the GreenfootSound class cannot be executed on that sound because there is no way to refer to it). Notice how line 5 above refers to the sound (by the 'backgroundMusic' variable whose reference is created at line 4, within the constructor. By moving line 4 outside the constructor, the reference will be maintained as long as the world object exists and you can refer to it by 'backgroundMusic' from any non-static method in the class.
You need to login to post a reply.