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

2013/3/8

Creating a mute button

SP00F3R SP00F3R

2013/3/8

#
I have two classes with images, one is a mute icon and one is a full volume icon. I'm looking to make the icons change when they are clicked and to either mute or unmute my game accordingly. Is anyone able to help me out? Many thanks, SP00F3R
danpost danpost

2013/3/8

#
Better would be to have just one class; and just change the image of the actor created from that class while the muting is being toggled. The main idea is shown below, but the name of the files will need adjusted.
private GreenfootSound sound = new GreenfootSound("sound.wav");
private boolean isMuted;

public void act()
{
    if(Greenfoot.mouseClicked(this))
    {
        isMuted = !isMuted;
        updateState();
    }
}

private void updateState()
{
    if(isMuted)
    {
        setImage("muted.png");
        sound.stop();
    }
    else
    {
        setImage("fullVolume.png");
        sound.play();
    }
}
The 'updateState' method can be called from the constructor of the class to initiate the state.
TomazVDSN TomazVDSN

2013/3/8

#
http://www.greenfoot.org/scenarios/7592
You need to login to post a reply.