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

2011/4/21

Sounds

jhadad jhadad

2011/4/21

#
Hi, i am making a game and i am trying to make a sound play once when a key is pressed (and held). Then, the sound needs to stop when i let go of the key. If anyone could help me with this I would really appreciate it. Thanks John
webmessia webmessia

2011/4/22

#
public class Example extends Actor {

    private GreenfootSound exampleSound = new GreenfootSound("soundfile.wav");

    public void act(){
        if(Greenfoot.isKeyDown("space")){
            exampleSound.playLoop();
        } else {
            exampleSound.stop();
        }
        // Rest of Code in Act goes here
    }
}
jhadad jhadad

2011/4/23

#
When i try to use this, i get an error on the private GreenfootSound file saying greenfoot.GreenfootSound is not public in greenfoot; cannot be accessed from out side package and im not sure what that means. Thanks for the help John
PiRocks PiRocks

2011/4/23

#
Make sure you have the newest form of Greenfoot. If your version is under 2.0, then GreenfootSound is unavailavble.
You need to login to post a reply.