refactor audio.crossfade

This commit is contained in:
PeaAshMeter 2026-01-19 00:21:21 +03:00
parent 9ad6c8bdfa
commit fc5a39b1d2

View File

@ -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,