forked from TomK32/Rogue-Beach-CA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sound_manager.lua
42 lines (36 loc) · 988 Bytes
/
sound_manager.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
do
-- will hold the currently playing sources
local sources = {}
-- check for sources that finished playing and remove them
-- add to love.update
function love.audio.update()
local remove = {}
for _,s in pairs(sources) do
if s:isStopped() then
remove[#remove + 1] = s
end
end
for i,s in ipairs(remove) do
sources[s] = nil
end
end
-- overwrite love.audio.play to create and register source if needed
local play = love.audio.play
function love.audio.play(what, how, loop)
local src = what
if type(what) ~= "userdata" or not what:typeOf("Source") then
src = love.audio.newSource(what, how)
src:setLooping(loop or false)
end
play(src)
sources[src] = src
return src
end
-- stops a source
local stop = love.audio.stop
function love.audio.stop(src)
if not src then return end
stop(src)
sources[src] = nil
end
end