improvement: only change current music when new

It'll avoid having the music resetting every time you enter a new map with the same music
(entering in a house for instance)
This commit is contained in:
Kazhnuz 2021-04-03 10:52:00 +02:00
parent fcafa9aa0f
commit be54412284

View file

@ -63,6 +63,8 @@ function OverWorld:new(area, playerx, playery)
self.message = "Test de message" self.message = "Test de message"
self.messageOpacity = 0 self.messageOpacity = 0
self.isPlaying = ""
self.events = EventManager(self) self.events = EventManager(self)
end end
@ -73,8 +75,12 @@ function OverWorld:updateCurrentMap(map)
end end
function OverWorld:playMapMusic(map) function OverWorld:playMapMusic(map)
self.assets:setMusic("assets/music/" .. map.music .. ".mp3") local newMusic = map.music
if (newMusic ~= self.isPlaying) then
self.assets:setMusic("assets/music/" .. newMusic .. ".mp3")
self.assets:playMusic() self.assets:playMusic()
self.isPlaying = newMusic
end
end end
function OverWorld:startEvent() function OverWorld:startEvent()