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

2011/12/15

Just an odd little bug :D.

darkmist255 darkmist255

2011/12/15

#
**FIXED** After my previous quarrel with some other classes, I've managed to iron out almost all of the bugs from my game, except this one. The following class has an interesting problem:
public class VolumeSelect extends Actor
{
    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;
            }         
        }
    }
}
Seems simple enough, though when it sets the volume to half (the image still changes) the audio is still muted until I set it to full. Now here's the code that is accessing the volume level:
public void addedToWorld(World world)
    {
        //load the injury sound
        injury.setVolume(0);
        injury.play();
        room = (Room)getWorld();
        volumeselect = room.volumeselect;
    }
    
    public void damagePlayer(int damage)
    {
        health = health - damage;
        injury.setVolume(volumeselect.volumeLevel);
        injury.play();
    }
Strange how it works for 0 and 100, but not for 50. Did I miss something in there?
kiarocks kiarocks

2011/12/15

#
turn the sound up and see if you can hear it and also try hard setting it to 50
darkmist255 darkmist255

2011/12/15

#
I hard set it to 50, no sound. Maybe that's the problem o.O!
kiarocks kiarocks

2011/12/15

#
try 75
darkmist255 darkmist255

2011/12/15

#
I ended up choosing 90, which (oddly) sounds like about half the volume. I thought that it was the percent of the volume, but oh well :D. Fixed now!
mjrb4 mjrb4

2011/12/16

#
Hmm, this may be because the volume is logarithmic and not linear. I *thought* we had something in there to convert it to linear, but I may be wrong!
darkmist255 darkmist255

2011/12/17

#
Ahh, I've never touched on logarithms. Heard lots about them, but never actually know what they are or what they do :D.
You need to login to post a reply.