Created
September 9, 2013 15:44
-
-
Save josefnpat/6497453 to your computer and use it in GitHub Desktop.
Play sounds all at once - raidho36
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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