Hello, I have a class Sound with 3 private GreenfootSounds, what I want is when the Player changes World the current music stops and the other one starts.
Here is what i have:
- Sound class:
I have in all Worlds a object of the Sound class.
-Play class:
I want that, for example, when i press the Play, the current sound, which is sound1, stop and the world changes.
What happens is, i press the Play, the world changes and the sound re-plays.
Appreciate any help.
private GreenfootSound sound1 = new GreenfootSound("sound1.mp3");
private GreenfootSound sound2 = new GreenfootSound("sound2.mp3");
private GreenfootSound sound3 = new GreenfootSound("sound3.mp3");
private GreenfootImage sound;
/**
* Constructor.
*/
public Sound()
{
sound = getImage();
sound.clear();
}
public void act()
{
// Add your action code here.
}
public void playSound1()
{
sound1.playLoop();
}
public void stopSound1()
{
sound1.stop();
}
public void playSound2()
{
sound2.playLoop();
}
public void stopSound2()
{
sound2.stop();
}
public void playSound3()
{
sound3.playLoop();
}
public void stopSound3()
{
sound3.stop();
}addObject(new Sound(), 0, 0);
public void act()
{
clickPlay();
playSound();
}
public void clickPlay()
{
World poke1 = new PokeWorld1();
if(Greenfoot.mousePressed(this))
{
setImage(play2);
}
if(Greenfoot.mouseClicked(this))
{
Greenfoot.setWorld(poke1);
poke1.addObject(new Player(), 170, 215);
stopSound();
}
}
public void playSound()
{
soundList=getWorld().getObjects(Sound.class);
soundList.get(0).playSound1();
}
public void stopSound()
{
soundList=getWorld().getObjects(Sound.class);
soundList.get(0).stopSound1();
}


