This site requires JavaScript, please enable it in your browser!
Greenfoot back
rachpaguia@gmail.com
rachpaguia@gmail.com wrote ...

2017/3/17

BACKGROUND MUSIC

Hello! What code must I use to only start the background music when run is pressed? My music has been playing even if my program hasn't started. Here is my code:
public class bg extends World
{
    GreenfootSound backgroundMusic = new GreenfootSound("music.mp3");
public bg()
    {//this sets the background     
super(600, 400, 1);
setBackground("Final ICT BG.png");
backgroundMusic.playLoop();
        
GreenfootImage bg = new GreenfootImage("Final ICT BG.png");
bg.scale(getWidth() +35, getHeight() +30);
setBackground(bg);
prepare();
valdes valdes

2017/3/17

#
Declare method started() in your world. Move line 8 there.
public void started() {
backgroundMusic.playLoop();
}
To end it when program stops
public void stopped() {
backgroundMusic.stop();
}
Thank you!!!
You need to login to post a reply.