We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Ess playback problem (Read 920 times)
Ess playback problem
Mar 8th, 2006, 6:42pm
 
I have a game where i play a sound upon a collision occuring in the game. If i have sound.play() in the collision detection method it only plays the first time a collision detection is detected. I then did sound.play(Ess.FOREVER) in the CD method and sound.stop() in the draw method. This worked but apart from that first collision the sketch paused for a quarter second on each collision making it not usable.

Is there a workaround for this? Thanks.
Re: Ess playback problem
Reply #1 - Oct 15th, 2007, 10:49pm
 
token -

This post is from a while ago so not sure if any advice is still helpful, but ...

I would try your first approach ... ie, sound.play() and then the next time you want to play it, call sound.stop() before calling play() again. You may want to wrap the sound.stop() in an if statement that checks .state to make sure the sound is in fact playing.

This may have performance implications though. I think a better approach would be to set some time (eg, millis() + 1000 if its a 1 second sound clip) and then in your draw loop check if millis() is >= to that time, and call sound.stop() when it is. That will always stop your sound after giving it a little time to play.

good luck-
R
Page Index Toggle Pages: 1