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

2012/8/16

Two sound queries

davemib123 davemib123

2012/8/16

#
Hi, I've got two sound related queries. The first is with my background sound, how do I stop it when the "pause" button is pressed. The second is with the bullet sound, how would I reduce the volume? I tried something similar to the way I inserted the background sound but then the bullet sound would not come with every bullet fired. scenario is here: http://www.greenfoot.org/scenarios/5799 Your help would be appreciated :)
DonaldDuck DonaldDuck

2012/8/16

#
For your first question, I am fairly certain in the World subclass, there are two methods called by Greenfoot, started() and stopped() (self explanatory). To edit what happens at these points, in your world subclass add this void:
public void stopped()
{
    MUSIC.stop();
}
or you can make it pause and resume when the scenario is started again. For your second question, well, you should find the answer here.
davemib123 davemib123

2012/8/16

#
Thanks started and stopped are world methods :).
davemib123 davemib123

2012/8/16

#
Still not sure on the first query, I tried this: variable and constructor:
    private GreenfootSound missileSound;

    public Hero(){
       missileSound = new GreenfootSound("laser_gu-public_d-312_hifi.mp3");
        missileSound.setVolume(35);
    }   
Space key to shoot:
        if (Greenfoot.isKeyDown("space") && shootLimiter > 8){

            shootLimiter = 0;
            //   Greenfoot.playSound("laser_gu-public_d-312_hifi.mp3");    
            missileSound.play();
            HeroMissile fire = new HeroMissile();
            getWorld().addObject(fire, getX() + xPosition, getY() + yPosition);
        }
sound doesnt play as it should, when bullets are fired you can not always hear the sound
davemib123 davemib123

2012/8/16

#
got it sorted, if i put it into the constructor it doesnt work :S - but if its in the space key section it works fine.
SPower SPower

2012/8/16

#
It would also work in the addedToWorld method, btw.
DonaldDuck DonaldDuck

2012/8/18

#
I think what SPower is saying is that you could put the missileSound in the HeroMissile class and in the addedToWorld method make the sound play. That way the sound plays 100% of the time when a bullet is fired.
You need to login to post a reply.