summaryrefslogtreecommitdiff
path: root/game/music.lua
blob: d9f3e91b854dbf5f2dd1dc15cf055cbaecc5af23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
local M = {}
M.__index = M
M.playing = nil

function M.new(assets)
	local new = setmetatable({}, M)
	new.assets = assets
	return new
end

function M:play(name)
	assert(self.assets.music[name], name.." isn't extant music")
	if M.playing ~= self.assets.music[name] then
        if M.playing then M.playing:stop() end
        self.assets.music[name]:seek(0)
        M.playing = self.assets.music[name]
    end
    self.assets.music[name]:setVolume(0.5)
	self.assets.music[name]:play()
    self.assets.music[name]:setLooping(true)
end

return M