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
![Twitter](/assets/twitter-4e19209ef84344ee0c433f4c7bad8d49.png)
![Twitter.hover](/assets/twitter.hover-1fb19a5bafc50deace8f88eaec867845.png)
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 } }