Gun sounds
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Gun sounds
Hey guys. So i need some help with gun sounds.I have a gun sound that plays every time the gun is shot, Problem is if you shoot rapidly it doesn't play the sound every time you shoot, I figured that's because it's only capable of playing the same sound once any given time and wont play it again until it's done playing the first one until the very end. So is there any good way to get around that? Thanks in advance.
- nevon
- Commander of the Circuloids
- Posts: 938
- Joined: Thu Feb 14, 2008 8:25 pm
- Location: Stockholm, Sweden
- Contact:
Re: Gun sounds
Save the sound as sound data, create a sound queue and every time you need to play the sound, create a new source from the sounddata and add it to the queue. Once it's finished playing, remove it from the queue.
- baconhawka7x
- Party member
- Posts: 491
- Joined: Mon Nov 21, 2011 7:05 am
- Location: Oregon, USA
- Contact:
Re: Gun sounds
What I do is, just before playing the sound, I stop the one before it...'
Code: Select all
love.audio.stop(gunsound)
love.audio.play(gunsound)
Re: Gun sounds
There's a lib meant to solve ths problem, but I can't remember its name...
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: Gun sounds
How did i not think of that shit...it's so simple..lolbaconhawka7x wrote:What I do is, just before playing the sound, I stop the one before it...'Code: Select all
love.audio.stop(gunsound) love.audio.play(gunsound)
Re: Gun sounds
Perhaps https://love2d.org/wiki/Minimalist_Sound_Manager?Nixola wrote:There's a lib meant to solve ths problem, but I can't remember its name...
EDITED: OMG 666 Posts! KARMA 13! Perfect combo!
- nevon
- Commander of the Circuloids
- Posts: 938
- Joined: Thu Feb 14, 2008 8:25 pm
- Location: Stockholm, Sweden
- Contact:
Re: Gun sounds
I think you're referring to TESound. There's also mine and bartbes' soundmanager.Nixola wrote:There's a lib meant to solve ths problem, but I can't remember its name...
Re: Gun sounds
Which concerning managing/queue sounds don't seem to do much more than minimalisticI think you're referring to TESound.
That appear require an account to even check it.There's also mine and bartbes' soundmanager.
- nevon
- Commander of the Circuloids
- Posts: 938
- Joined: Thu Feb 14, 2008 8:25 pm
- Location: Stockholm, Sweden
- Contact:
Re: Gun sounds
What the...? That's the OSS fork. Why the heck is that private...?coffee wrote:That appear require an account to even check it.There's also mine and bartbes' soundmanager.
Anyway, here's the soundmanager:
Code: Select all
soundmanager = {}
soundmanager.queue = {}
soundmanager.playlist = {}
soundmanager.currentsong = -1
local function shuffle(a, b)
return math.random(1, 2) == 1
end
--do the magic
function soundmanager:play(sndData)
--make a source out of the sound data
local src = love.audio.newSource(sndData, "static")
--put it in the queue
table.insert(self.queue, src)
--and play it
love.audio.play(src)
end
--do the music magic
function soundmanager:playMusic(first, ...)
--stop all currently playing music
for i, v in ipairs(self.playlist) do
love.audio.stop(v)
end
--decide if we were passed a table or a vararg,
--and assemble the playlist
if type(first) == "table" then
self.playlist = first
else
self.playlist = {first, ...}
end
self.currentsong = 1
--play
love.audio.play(self.playlist[1])
end
--do some shufflin'
function soundmanager:shuffle(first, ...)
local playlist
if type(first) == "table" then
playlist = first
else
playlist = {first, ...}
end
table.sort(playlist, shuffle)
return unpack(playlist)
end
--update
function soundmanager:update(dt)
--check which sounds in the queue have finished, and remove them
local removelist = {}
for i, v in ipairs(self.queue) do
if v:isStopped() then
table.insert(removelist, i)
end
end
--we can't remove them in the loop, so use another loop
for i, v in ipairs(removelist) do
table.remove(self.queue, v-i+1)
end
--advance the playlist if necessary
if self.currentsong ~= -1 and self.playlist and self.playlist[self.currentsong]:isStopped() then
self.currentsong = self.currentsong + 1
if self.currentsong > #self.playlist then
self.currentsong = 1
end
love.audio.play(self.playlist[self.currentsong])
end
end
Re: Gun sounds
Thanks nevon, why you and bartbes (if you don't mind) don't add it to lib section? More choices is always better.nevon wrote: What the...? That's the OSS fork. Why the heck is that private...?
Anyway, here's the soundmanager:
Who is online
Users browsing this forum: Google [Bot] and 3 guests