summaryrefslogtreecommitdiffhomepage
path: root/music.lua
blob: 1ac26bbfa27b69fcfc32fc55f32ee2600622d0d5 (plain)
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
-- `Music`
-- Simple music player object that plays and loops selected track in single Scene.

-- WHOLE CODE HAS FLAG OF "need a cleanup"

-- Metatable of `Music`
-- nils initialized in constructor
Music = {
	track = nil,
	source = nil
}
function Music:new(track)
	-- Meta
	local o = {}
	setmetatable(o, self)
	self.__index = self
	-- Init
	o.track = track
	o.source = love.audio.newSource("assets/music/" .. o.track)
	o.source:setLooping(true)
	o.source:setVolume(.7)
	o.source:play()
	return o
end
function Music:delete()
	self.source:stop()
end