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

2014/6/27

Playing Background music does not work?!

Svek Svek

2014/6/27

#
Im trying to play background music on my game with this code:
private GreenfootSound music = new GreenfootSound("Zelda Main Theme Song.mp3");    
   
    public void Music()
    {
 
        {    
            music.playLoop();    
        }     

    }
The code is in the Main World and the music is in the sound folder Please help!
danpost danpost

2014/6/27

#
Are you calling 'Music();' from anywhere? You can create as many methods as you would like; but, you still need to call them to execute. In this case, I would eliminate the method and just call 'music.playLoop();' at the place where you would call that method.
Svek Svek

2014/6/27

#
Thanks it works now but how do i stop it now? I want the music to stop if the world switches
danpost danpost

2014/6/27

#
From your Main world:
music.stop();
From an Actor class:
((Main)getWorld()).music.stop();
As an alternative, you could make the 'music' field a 'static' field and use the following from anywhere:
Main.music.stop();
You need to login to post a reply.