I have looked around but cannot find much about this. my game ha 3 levels and I want it to play different bg music for each level. so far I have the level1 code but for some reason when I go to level 2 it continues to play the music from level 1 at the same time as the music from level 2. level 1 music will pause when I pause the game but only on level 1.
level 1 code
level 2 code:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class MyWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Level1 extends World
{
GreenfootSound backgroundMusic = new GreenfootSound("level1 theme.mp3");
private int [] [] mazeMap = {
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,2,1,0,0,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1},
{1,0,1,1,0,3,0,0,1,1,0,1,1,1,1,0,1,0,1,0,0,1,1,1},
{1,0,1,1,0,1,1,0,1,1,0,0,0,3,0,4,1,1,1,1,0,1,1,1},
{1,0,1,0,0,0,0,0,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1},
{1,0,1,0,1,1,0,1,1,0,1,0,0,1,1,1,1,1,1,0,4,1,1,1},
{1,0,0,0,0,0,0,1,1,0,1,0,1,1,1,1,1,1,1,0,1,1,1,1},
{1,8,4,1,1,1,0,1,1,0,0,0,0,0,0,1,1,0,0,3,0,0,0,1},
{1,0,1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,0,1},
{1,0,1,0,0,1,7,1,1,1,0,1,1,1,1,0,1,0,9,1,1,1,0,1},
{1,0,1,1,1,1,5,0,0,1,0,0,0,1,1,0,1,1,0,1,0,0,0,1},
{1,0,1,1,1,1,1,1,0,1,0,1,1,0,1,0,1,1,7,1,0,1,1,1},
{1,0,1,1,1,1,1,0,0,0,3,0,3,0,0,0,1,0,5,0,0,1,1,1},
{1,0,0,3,0,0,0,0,1,1,1,1,1,1,1,7,1,0,1,1,0,0,0,1},
{1,1,4,1,1,1,1,0,0,0,1,1,1,1,1,5,0,0,1,1,1,1,0,6},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
};
/**
* Constructor for objects of class MyWorld.
*
*/
public Level1()
{
super(1200, 800, 1);
backgroundMusic.playLoop();
placeBlocks();
prepare();
}
public void started()
{
backgroundMusic.playLoop();
}
public void stopped()
{
backgroundMusic.pause();
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class MyWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Level2 extends World
{
GreenfootSound backgroundMusic = new GreenfootSound("level2 theme.mp3");
private int [] [] mazeMap = {
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,2,0,0,0,1,1,0,0,0,1,0,1,1,0,0,0,0,0,0,1,1,1,1},
{1,1,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,1,0,1,4,1,1},
{1,0,0,1,1,1,1,0,1,0,1,1,0,1,1,1,1,1,1,0,0,0,1,1},
{1,0,1,0,3,0,0,0,1,0,1,1,0,1,1,0,0,1,1,7,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1,0,4,1,1,1,0,0,1,5,0,1,1,1},
{1,0,0,0,0,0,0,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,1},
{1,0,1,1,1,1,0,0,0,0,3,0,3,0,3,1,1,0,1,1,1,4,1,1},
{1,0,1,1,1,1,0,1,0,1,1,1,1,1,1,1,0,0,0,3,0,0,0,1},
{1,0,0,0,0,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1},
{1,0,1,1,1,1,0,0,0,1,1,0,0,0,0,0,1,1,0,1,1,0,1,1},
{1,1,1,1,1,1,1,1,0,1,1,1,1,0,1,1,1,0,0,1,1,0,0,1},
{1,1,1,1,1,1,1,0,0,3,4,0,0,0,1,1,1,1,0,1,1,1,0,1},
{1,1,0,3,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,1,1,1,0,1},
{1,1,0,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,6},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
};
/**
* Constructor for objects of class MyWorld.
*
*/
public Level2()
{
super(1200, 800, 1);
backgroundMusic.playLoop();
placeBlocks();
prepare();
}
public void started()
{
backgroundMusic.playLoop();
}
public void stopped()
{
backgroundMusic.pause();
}

