Skip to content

Instantly share code, notes, and snippets.

@josefnpat
Created September 9, 2013 15:44
Show Gist options
  • Save josefnpat/6497453 to your computer and use it in GitHub Desktop.
Save josefnpat/6497453 to your computer and use it in GitHub Desktop.
Play sounds all at once - raidho36
local _channels = { }
local _sounds = { }
_sounds.sound1 = love.audio.newSoundData ( "sound1.ogg" )
_sounds.sound2 = love.audio.newSoundData ( "sound2.ogg" )
-- etc.
function playSound ( sound )
if not _channels[ sound ] then _channels[ sound ] = { } end
local chan = _channels[ sound ]
local free = 0
for num, src in pairs ( chan ) do
if src:isStopped ( ) then free = num; break end
end
if free == 0 then
free = #chan + 1
chan[ free ] = love.audio.newSource ( _sounds[ sound ] )
end
chan[ free ]:play ( )
end
playSound ( "sound1" )
playSound ( "sound1" )
playSound ( "sound1" )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment