Sounds only playing from time to time

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
iPoisonxL
Party member
Posts: 227
Joined: Wed Feb 06, 2013 3:53 am
Location: Australia
Contact:

Sounds only playing from time to time

Post by iPoisonxL »

This game I'm making has a guy getting slapped. I added sound effects. Sounds simple enough, load the 4, make a math.random(1,4) on a table to randomly play one of the 4 sounds. It works correctly, but sometimes the sounds just... don't play? I tried removing the math.random and only playing 1 sound, but it only plays the first time, and like the 7th time. It's not with the math.random, that's what I know. It's like love2d just decides to not play the sound.
here's the file...
slapnorm.love
(158.24 KiB) Downloaded 38 times
Here's the bit where I load the sounds (in norm.lua):

Code: Select all

sounds = {}

for x = 1, 4 do
		sounds[x] = love.audio.newSource('/res/slaps/slap'..x..'.ogg')
end
and here's the bit where I play the sounds (in main.lua):

Code: Select all

function love.keypressed(k)
        local rand = math.random(1,4)
	if (k == 'x' or
	k == 'z' or
	k == ' ') then
		love.audio.play(sounds[rand])
		hand.slap()
	end
end
thanks in advance.

P.S. also, I haven't tried making them into .ogg's. I'll try it now
EDIT: I just tried putting OGG's instead, and it works slightly better. It stills sometimes doesn't play... I still need some help. I updated the file with the new ogg files.

Code: Select all

      L
    L Ö
    Ö V
L Ö V E
Ö B E
V E
E Y
Website
Automatik
Citizen
Posts: 57
Joined: Sun Feb 17, 2013 7:05 pm

Re: Sounds only playing from time to time

Post by Automatik »

Try to append a love.audio.stop(sounds[rand]) before the love.audio.play(sounds[rand]).
User avatar
iPoisonxL
Party member
Posts: 227
Joined: Wed Feb 06, 2013 3:53 am
Location: Australia
Contact:

Re: Sounds only playing from time to time

Post by iPoisonxL »

Automatik wrote:Try to append a love.audio.stop(sounds[rand]) before the love.audio.play(sounds[rand]).
Thanks, it worked

Code: Select all

      L
    L Ö
    Ö V
L Ö V E
Ö B E
V E
E Y
Website
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 47 guests