Page 1 of 1

How do sound effects work?

Posted: Wed Apr 20, 2016 3:46 am
by Joelrodiel
I have tried lots of things, but still don't know how to play sound effects. By sound effects I mean playing a certain sound for a certain time and then making it stop COMPLETELY. I have looked everywhere but can't seem to find the answer, maybe because its a really noobish question, I don't know. Every time I play sounds they just end up looping. Thanks in advance.

Re: How do sound effects work?

Posted: Wed Apr 20, 2016 12:42 pm
by pgimeno
Sounds do not loop unless you tell them to.

Code: Select all

local snd = love.audio.newSource('mysound.ogg')
-- snd:setLooping(true) -- if you enable this, it will loop; otherwise it won't
snd:play()
If your sound loops anyway, you may have found a bug. Can you attach a short .love file that exhibits the problem?

Re: How do sound effects work?

Posted: Wed Apr 20, 2016 1:22 pm
by zorg
Also, make sure you're not calling, for example, snd:play(), going by pgimeno's example, in love.update just like that, since that's not how it works. :3

Re: How do sound effects work?

Posted: Wed Apr 20, 2016 1:40 pm
by Joelrodiel
Here is one of my attempts of making a sound effect. Just some dumb thing I made to test sound effects and pictures. Also, thanks for the fast replies :awesome:

Re: How do sound effects work?

Posted: Wed Apr 20, 2016 1:53 pm
by pgimeno
The problem is what zorg said. You keep triggering bop:play(). Try adding pressed = false after bop:play().

You may also want to have another variable to track whether the button was pressed in the previous frame, so that it only plays when it was off in the previous frame and on in the current frame. That will prevent it to keep playing while pressed.

Re: How do sound effects work?

Posted: Wed Apr 20, 2016 2:02 pm
by zorg
I'd urge you not to open this link (just yet), but it has a solution: http://pastebin.com/q201JjHf

Re: How do sound effects work?

Posted: Wed Apr 20, 2016 2:59 pm
by Joelrodiel
zorg wrote:I'd urge you not to open this link (just yet), but it has a solution: http://pastebin.com/q201JjHf
So should I open it? :0

Re: How do sound effects work?

Posted: Wed Apr 20, 2016 3:05 pm
by Joelrodiel
So I fixed it. Now I made it so when you click it will make the sound effect and change the picture. Thank you so much for your quick responses. Have a nice day.