refactor audio.crossfade
This commit is contained in:
parent
9ad6c8bdfa
commit
fc5a39b1d2
@ -23,16 +23,11 @@ local function new(musicVolume, soundVolume)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function audio:update(dt)
|
function audio:update(dt)
|
||||||
if self.animationNode and self.animationNode.state == "running" then
|
if not self.animationNode then return end
|
||||||
self.animationNode:update(dt)
|
self.from:setVolume(self.musicVolume - self.animationNode:getValue() * self.musicVolume)
|
||||||
self.from:setVolume(self.musicVolume - self.animationNode:getValue() * self.musicVolume)
|
self.to:setVolume(self.animationNode:getValue() * self.musicVolume)
|
||||||
self.to:setVolume(self.animationNode:getValue() * self.musicVolume)
|
self.animationNode:update(dt)
|
||||||
-- print(self.animationNode.t)
|
-- print(self.animationNode.t)
|
||||||
elseif self.animationNode and self.animationNode.state == "finished" then
|
|
||||||
self.from:stop()
|
|
||||||
self.animationNode:finish()
|
|
||||||
self.animationNode = nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- if from is nil, than we have fade in to;
|
--- if from is nil, than we have fade in to;
|
||||||
@ -53,6 +48,8 @@ function audio:crossfade(from, to, ms)
|
|||||||
onEnd = function()
|
onEnd = function()
|
||||||
self.from:setVolume(0)
|
self.from:setVolume(0)
|
||||||
self.to:setVolume(self.musicVolume)
|
self.to:setVolume(self.musicVolume)
|
||||||
|
self.from:stop()
|
||||||
|
self.animationNode = nil
|
||||||
print("[Audio]: Crossfade done")
|
print("[Audio]: Crossfade done")
|
||||||
end,
|
end,
|
||||||
duration = ms or 1000,
|
duration = ms or 1000,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user