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
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
}
}