diff --git a/lib/audio.lua b/lib/audio.lua index 3331ab5..eaa7652 100644 --- a/lib/audio.lua +++ b/lib/audio.lua @@ -23,16 +23,11 @@ local function new(musicVolume, soundVolume) end function audio:update(dt) - if self.animationNode and self.animationNode.state == "running" then - self.animationNode:update(dt) - self.from:setVolume(self.musicVolume - self.animationNode:getValue() * self.musicVolume) - self.to:setVolume(self.animationNode:getValue() * self.musicVolume) - -- print(self.animationNode.t) - elseif self.animationNode and self.animationNode.state == "finished" then - self.from:stop() - self.animationNode:finish() - self.animationNode = nil - end + if not self.animationNode then return end + self.from:setVolume(self.musicVolume - self.animationNode:getValue() * self.musicVolume) + self.to:setVolume(self.animationNode:getValue() * self.musicVolume) + self.animationNode:update(dt) + -- print(self.animationNode.t) end --- if from is nil, than we have fade in to; @@ -53,6 +48,8 @@ function audio:crossfade(from, to, ms) onEnd = function() self.from:setVolume(0) self.to:setVolume(self.musicVolume) + self.from:stop() + self.animationNode = nil print("[Audio]: Crossfade done") end, duration = ms or 1000,