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

2011/12/10

Just a quick question.

darkmist255 darkmist255

2011/12/10

#
** Solved this like 2 minutes after posting ** I feel like I'm spamming Greenfoot today :O. Guess I'm programming lots today. I have a simple actor that lets the player change the volume, or so I think it's simple? This is it:
public class VolumeSelect extends Actor
{
    public int volumeLevel = 100;
    
    public void act() 
    {
        checkClick();
    }    
    
    public void checkClick()
    {
        if(Greenfoot.mouseClicked(this))
        {
            if(volumeLevel == 0)
            {
                setImage("VolumeHalf.png");
                volumeLevel = 50;
            }
            if(volumeLevel == 50)
            {
                setImage("VolumeFull.png");
                volumeLevel = 100;
            }
            if(volumeLevel == 100)
            {
                setImage("VolumeOff.png");
                volumeLevel = 0;
            }
        }
    }
}
For some reason it starts out at 100% volume with VolumeFull.png, but after being clicked it just stays muted. Why is this? I've tried a few things but nothing seems to affect it.
darkmist255 darkmist255

2011/12/10

#
Nevermind, just realised that I have my if's in an ascending order, so it would always execute the last one last. I just made them "else if" and it worked :D. One problem though, when I set volumeLevel to 50, there's no audio? Here's the relevant code: In "Spikes.class"
    Room room = (Room)getWorld();
    VolumeSelect volumeselect = room.volumeselect;
    GreenfootSound injury = new GreenfootSound("Injury.wav");

private int delay = 0;
    
    public void act() 
    {
        if(delay > 0)
        {
            delay = (delay - 1);
        }
    }
    
    public void spikeDamagePlayer()
        {
            if(delay <= 0)
            {
                //make it damage player
                stats.damagePlayer(1);
                delay = 40;
                
                injury.setVolume(volumeselect.volumeLevel);
                injury.play();
            }
        }
and in "VolumeSelect.class":
{
    public int volumeLevel = 100;
    
    public void act() 
    {
        checkClick();
    }    
    
    public void checkClick()
    {
        if(Greenfoot.mouseClicked(this))
        {
            if(volumeLevel == 100)
            {
                setImage("VolumeOff.png");
                volumeLevel = 0;
            }
            else if(volumeLevel == 50)
            {
                setImage("VolumeFull.png");
                volumeLevel = 100;
            }
            else if(volumeLevel == 0)
            {
                setImage("VolumeHalf.png");
                volumeLevel = 50;
            }         
        }
    }
}
I can't see any problems :/...
You need to login to post a reply.