summaryrefslogtreecommitdiffhomepage
path: root/not/MusicPlayer.lua
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-06-15 17:21:02 +0200
committerAki <nthirtyone@gmail.com>2017-06-15 17:21:02 +0200
commit2c458f0c756ebe577083a7cc972a07e870cb0ba9 (patch)
tree7f9bf44504deaf3a3f9e9abb5116da6d6ad9f9bc /not/MusicPlayer.lua
parenta00ac10a0c3654dccf7c8c92da6d8666f2f7ac48 (diff)
downloadroflnauts-2c458f0c756ebe577083a7cc972a07e870cb0ba9.zip
roflnauts-2c458f0c756ebe577083a7cc972a07e870cb0ba9.tar.gz
roflnauts-2c458f0c756ebe577083a7cc972a07e870cb0ba9.tar.bz2
Music renamed to MusicPlayer
changed behaviour to use static table for sources need to change dependencies now
Diffstat (limited to 'not/MusicPlayer.lua')
-rw-r--r--not/MusicPlayer.lua34
1 files changed, 34 insertions, 0 deletions
diff --git a/not/MusicPlayer.lua b/not/MusicPlayer.lua
new file mode 100644
index 0000000..1e65e3b
--- /dev/null
+++ b/not/MusicPlayer.lua
@@ -0,0 +1,34 @@
+require "not.object"
+
+--- `MusicPlayer`
+-- 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:setTrack(trackName)
+end
+
+function MusicPlayer:delete ()
+ self.source:stop()
+end
+
+function MusicPlayer:setTrack (trackName)
+ if self.source then
+ self.source:stop()
+ end
+ if MusicPlayer.TRACKS[trackName] then
+ self.source = MusicPlayer.TRACKS[trackName]
+ else
+ local source = love.audio.newSource("assets/music" .. trackName)
+ source:setLooping(true)
+ source:setVolume(.7)
+ self.source = source
+ MusicPlayer.TRACKS[trackName] = source
+ end
+ self.source:play()
+end
+
+return MusicPlayer