From fc5a39b1d28f1f6ddb970003a6e167b2519a6173 Mon Sep 17 00:00:00 2001 From: PeaAshMeter Date: Mon, 19 Jan 2026 00:21:21 +0300 Subject: [PATCH] refactor audio.crossfade --- lib/audio.lua | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) 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,