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

2023/9/11

How would I make a sound play til I stop holding a button

Bobert Bobert

2023/9/11

#
I am new to greenfoot, and trying to make a sound sustain while key is pressed. *context* Making a Piano where I can hold a key to sustain sound. (right now all it does it just play a short sound when I press) So far what I can only think of is: make an if statement where: -If a Key is pressed and held for <1 second, loop play a sound. (or play a separate version of the sound, and maybe "if key is not pressed", Stop playing sound (dont know if its possible, maybe with sound.stop ()) The issue is I don't know if there's a way I can track time, and it would cause the sound to not "sustain" but just loop play. If I used a different modified audio file, it would work, but only for as long as the file plays the audio. So If I held the key for 2 seconds, and the audio was 3 seconds, it Would work but still play for the remaining 1 second even if the key is not pressed. The same applies if I hold longer than the audio clip lasts, it just ends there. So basically I am asking: -How can I make so I can record time? (so I can make so if keypressed is <1second, play sustain sound. -Is it possible to even sustain a sound (or do I have to use a separate file and just mistime it)
danpost danpost

2023/9/12

#
Bobert wrote...
I am new to greenfoot, and trying to make a sound sustain while key is pressed. ... make an if statement where: -If a Key is pressed and held for <1 second, loop play a sound. (or play a separate version of the sound, and maybe "if key is not pressed", Stop playing sound (dont know if its possible, maybe with sound.stop ())
Did you try this? What was your attempted codes?
You need to login to post a reply.