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

2013/6/3

Controlling Sound For Game --- Need Help!

geekykid2013 geekykid2013

2013/6/3

#
I have added two speaker buttons to my game settings menu to control sound On and OFF. My sound file is called breathe.mp3 and is located in my FrontPage Screen class. I have added the following sound methods to my Volume Slider class but I still cannot control the sound. what am i doing wrong here?
landry landry

2013/6/3

#
do you have this in your world? GreenfootSound backgroundMusic = new GreenfootSound("breathe.mp3");//should be declared before the constructor. public void stopped() { backgroundMusic.pause(); //stop the background music } public void started() { backgroundMusic.playLoop(); //plays the background music }
landry landry

2013/6/3

#
In the " sound on "button you can try : GreenfootSound backgroundMusic = new GreenfootSound("breathe.mp3");//should be declared before the constructor. public void soundOn() { if (Greenfoot.mouseClicked(this)) { backgroundMusic.playLoop(); } } In the " sound off "button you can try: GreenfootSound backgroundMusic = new GreenfootSound("breathe.mp3");//should be declared before the constructor. public void soundOff() { if (Greenfoot.mouseClicked(this)) { backgroundMusic.pause(); } } Note: don't forget to declare soundOff() and soundOn() in their reespective prepare methods if needed.
geekykid2013 geekykid2013

2013/6/3

#
sorry, but I'm not sure how to do declare these methods properly can you help?
geekykid2013 geekykid2013

2013/6/3

#
I have put the following prepare method in to my respective SoundOn() and SoundOff classes. I this what you mean? public void prepare(); { SoundOn(); } GreenfootSound backgroundMusic = new GreenfootSound("breathe.mp3");//should be declared before the constructor.
landry landry

2013/6/3

#
you know what just upload your scenario later on and i'll try to guide you trough that .
geekykid2013 geekykid2013

2013/6/3

#
here is the code to my SoundOn() class?
geekykid2013 geekykid2013

2013/6/3

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class SoundOn here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class SoundOn extends VolumeSlider
{

    /**
     * Act - do whatever the SoundOn wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
  
    
    GreenfootSound backgroundMusic = new GreenfootSound("breathe.mp3"); //should be declared before the constructor
    
    public void SoundOn() 
    {
        if(Greenfoot.mouseClicked(this))
        {
            setImageSpeakerOn();
            //stopBGM();
            backgroundMusic.playLoop();
        }
    }    
}
geekykid2013 geekykid2013

2013/6/3

#
I need further help on my game. I have been asked to declare two methods to my code SoundOn() and SoundOff() in their respective prepare methods how do i do this?
geekykid2013 geekykid2013

2013/6/3

#
I have now added the two methods SoundOn() and SoundOff() in their respective prepare methods - with no syntax errors, but I can't turn the sound loop on and off. Also my set image doesn't change according -- can you help?
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class SoundOn here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class SoundOn extends VolumeSlider
{
    
    /**
     * Act - do whatever the SoundOn wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    GreenfootSound backgroundMusic = new GreenfootSound("breathe.mp3"); //should be declared before the constructor
    
    public SoundOn()
    {
        prepare();
    }
    
    public void SoundOn() 
    {
        if(Greenfoot.mouseClicked(this))
        {
            setImageSpeakerOff();
            //stopBGM();
            backgroundMusic.playLoop();
        }
    }
    
    private void prepare()
    {
        SoundOn();
    }
}
landry landry

2013/6/3

#
http://www.greenfoot.org/scenarios/8649 look at what i made to demonstrate what i mean , it should be helpful
You need to login to post a reply.