Hello
I want to know how to create a mute background sound button that activates and deactivates as I click on it.
I also want it to alternate between 2 images as it goes on and off.
Thank you
private GreenfootSound backgroundMusic = new GreenfootSound("Adventure1.mp3");
//start the music in constructor or when "run" is pressed
public void unmute()
{
backgroundMusic.playLoop();
}
public void mute()
{
backgroundMusic.pause();
}private GreenfootImage[] images = {new GreenfootImage("unmuted.png"), new GreenfootImage("muted.png")};
public SoundButton()
{
setImage(images[0]);
}
public void act()
{
if (Greenfoot.mousePressed(this))
{
if (getImage() == images[0])
{
setImage(images[1]);
((WorldName) getWorld()).mute();
}
else
{
setImage(images[0]);
((WorldName) getWorld()).unmute();
}
}
}