How do sound effects work?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Joelrodiel
Prole
Posts: 27
Joined: Wed Apr 20, 2016 3:40 am

How do sound effects work?

Post 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.
User avatar
pgimeno
Party member
Posts: 3541
Joined: Sun Oct 18, 2015 2:58 pm

Re: How do sound effects work?

Post 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?
User avatar
zorg
Party member
Posts: 3435
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How do sound effects work?

Post 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
Last edited by zorg on Wed Apr 20, 2016 1:51 pm, edited 1 time in total.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Joelrodiel
Prole
Posts: 27
Joined: Wed Apr 20, 2016 3:40 am

Re: How do sound effects work?

Post 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:
Attachments
geltaingame.love
(299.19 KiB) Downloaded 163 times
User avatar
pgimeno
Party member
Posts: 3541
Joined: Sun Oct 18, 2015 2:58 pm

Re: How do sound effects work?

Post 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.
User avatar
zorg
Party member
Posts: 3435
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How do sound effects work?

Post by zorg »

I'd urge you not to open this link (just yet), but it has a solution: http://pastebin.com/q201JjHf
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Joelrodiel
Prole
Posts: 27
Joined: Wed Apr 20, 2016 3:40 am

Re: How do sound effects work?

Post 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
User avatar
Joelrodiel
Prole
Posts: 27
Joined: Wed Apr 20, 2016 3:40 am

Re: How do sound effects work?

Post 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.
Attachments
gelatinRINKAH.love
(299.2 KiB) Downloaded 174 times
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 14 guests