This site requires JavaScript, please enable it in your browser!
Greenfoot back
Yuki
Yuki wrote ...

2016/4/6

How To Create Mute Button

Yuki Yuki

2016/4/6

#
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
Super_Hippo Super_Hippo

2016/4/6

#
With what part are you having trouble with? Do it step by step. I am sure you can at least do some of the steps on your own.
Yuki Yuki

2016/4/6

#
I actually just started today so I am not really familiar with this. But I did try making a mute and unmute button but for some reason it doesn't even stop the music in the background or switch between different images.
Super_Hippo Super_Hippo

2016/4/6

#
Show the code you are currently using in this mute button class and for creating the background music if that is in a different class.
Yuki Yuki

2016/4/6

#
GreenfootSound backgroundMusic = new GreenfootSound("Adventure1.mp3"); backgroundMusic.playLoop(); I am having problem with the Actor. Don't know what code to make it mute background sound.
Super_Hippo Super_Hippo

2016/4/6

#
Use the first line outside methods. Then you can use 'backgroundMusic.pause();' to pause it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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();
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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();
        }
    }
}
You need to login to post a reply.