Hi does anyone know how to set a new background music? I have a bg music for my program with a game background , and im planning to put another one for my game over background
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();
//if("enter".equals(Greenfoot.getKey()));
}
private int spawnTimer;
public void act()
{ checkForSpawning();
}
private void checkForSpawning()
// this action adds an actor after every particular time
{
spawnTimer = (spawnTimer+1)%500;
if (spawnTimer%55 == 0) addObject(new A(), 150, 0);
if (spawnTimer%40 == 0) addObject(new L(), 250, 0);
if (spawnTimer%32 == 0) addObject(new H(), 60, 0);
if(spawnTimer%87 == 0)addObject(new I(), 330, 0);
if(spawnTimer%95 == 0)addObject(new O(), 520, 0);
if(spawnTimer%68 == 0)addObject(new R(), 400, 0);
}
private void prepare()
//this prepares objects and adds them to the world before program begins
{
}
public void gameOver()
{
removeObjects(getObjects(Actor.class));
GreenfootImage bg = new GreenfootImage("Go.png");
bg.scale(getWidth(), getHeight());
setBackground(bg);
backgroundMusic.pause();
GreenfootSound backgroundMusic = new GreenfootSound("go.mp3");
Greenfoot.stop();
}
}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();
//if("enter".equals(Greenfoot.getKey()));
}
private int spawnTimer;
public void act()
{ checkForSpawning();
}
private void checkForSpawning()
// this action adds an actor after every particular time
{
spawnTimer = (spawnTimer+1)%500;
if (spawnTimer%55 == 0) addObject(new A(), 150, 0);
if (spawnTimer%40 == 0) addObject(new L(), 250, 0);
if (spawnTimer%32 == 0) addObject(new H(), 60, 0);
if(spawnTimer%87 == 0)addObject(new I(), 330, 0);
if(spawnTimer%95 == 0)addObject(new O(), 520, 0);
if(spawnTimer%68 == 0)addObject(new R(), 400, 0);
}
private void prepare()
//this prepares objects and adds them to the world before program begins
{
}
public void gameOver()
{
removeObjects(getObjects(Actor.class));
GreenfootImage bg = new GreenfootImage("Go.png");
bg.scale(getWidth(), getHeight());
setBackground(bg);
backgroundMusic.stop();
backgroundMusic = new GreenfootSound("go.mp3");
GreenfootSound backgroundMusic = new GreenfootSound("go.mp3");
Greenfoot.stop();
}
}backgroundMusic.playLoop();
backgroundMusic.play();