From 0b3de32ee8b9d79d7b818a6742ab577ff47525e6 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 10 Jul 2017 21:16:35 +0200 Subject: MusicPlayer now don't share sources --- not/MusicPlayer.lua | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/not/MusicPlayer.lua b/not/MusicPlayer.lua index 84f5384..d2a89c3 100644 --- a/not/MusicPlayer.lua +++ b/not/MusicPlayer.lua @@ -4,14 +4,13 @@ require "not.Object" -- Simple music player object that plays and loops selected track. MusicPlayer = Object:extends() -MusicPlayer.TRACKS = {} - --- TODO: trackName should be passed without file extension. function MusicPlayer:new (trackName) + self.tracks = {} self:setTrack(trackName) end function MusicPlayer:delete () + self.tracks = nil self.source:stop() end @@ -19,14 +18,14 @@ function MusicPlayer:setTrack (trackName) if self.source then self.source:stop() end - if MusicPlayer.TRACKS[trackName] then - self.source = MusicPlayer.TRACKS[trackName] + if self.tracks[trackName] then + self.source = self.tracks[trackName] else local source = love.audio.newSource("assets/music/" .. trackName) source:setLooping(true) source:setVolume(.7) self.source = source - MusicPlayer.TRACKS[trackName] = source + self.tracks[trackName] = source end self.source:play() end -- cgit v1.1