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

2015/3/8

Change volume of bullet sound

DarkGhost DarkGhost

2015/3/8

#
Hi, how do I change the volume of a sound file that plays? I've tried lowering the sound in audacity but that does nothing when playing the file through greenfoot. I did searches and it seems that I have to use "public int getVolume()" but I have no idea how to implement this... Any help would be greatly appreciated :) Here's my code, as you can see it plays the gun shot sound every time the player fires a bullet.
        if (shotTimer >0) {
            shotTimer = shotTimer -1;}
        else if (Greenfoot.isKeyDown("space") )
        {
            getWorld().addObject(new Bullet1(getRotation()), getX(), getY());
            shotTimer = 10;
            Greenfoot.playSound("Gun_Shoot2.wav");
        } 
danpost danpost

2015/3/8

#
'setVolume' is an instance method that must be executed on an object created from the GreenfootSound class:
GreenfootSound  sound = new GreenfootSoun("Gun_Shoot2.wav"); // create a sound object
sound.setVolume(25); // adjust the volume of the sound
sound.play(); // play the sound
DarkGhost DarkGhost

2015/3/8

#
Ah i see, hmm it says <identifier> expected after the Volume in setVolume
DarkGhost DarkGhost

2015/3/8

#
Wait never mind i put it in the wrong place, it works now :) thank you very much for your help! :)
You need to login to post a reply.