Is it possible to have a button for music on and off and it will actually turn music on and off just by a click of the button
boolean playMusic = true;
GreenfootSound sound = new GreenfootSound("Name.FileFormat");GreenfootImage music= new GreenfootImage("images/speaker.png");
if (Greenfoot.mouseClicked(this) && !playMusic) {
playMusic = true;
} else if(Greenfoot.mouseClicked(this) && playMusic){
playMusic = false;
}
if(playMusic){
sound.playLoop();
} else{
sound.stop();
}
setImage(img);
boolean playMusic = true;
boolean playMusic = true;
GreenfootSound sound = new GreenfootSound("Name.FileFormat");
// write the location, name and file format of your music file
GreenfootImage music= new GreenfootImage("images/speaker.png");
// write the location, name and file format of your image file
public void act(){
if (Greenfoot.mouseClicked(this) && !playMusic) {
playMusic = true;
} else if(Greenfoot.mouseClicked(this) && playMusic){
playMusic = false;
}
if(playMusic){
sound.playLoop();
} else{
sound.stop();
}
setImage(img);
}