im undone, CROSSFADE DONE
This commit is contained in:
parent
f900e89a82
commit
2c8b65e1ae
@ -5,6 +5,8 @@ local AnimationNode = require "lib.animation_node"
|
|||||||
--- @field musicVolume number
|
--- @field musicVolume number
|
||||||
--- @field soundVolume number
|
--- @field soundVolume number
|
||||||
--- @field animationNode AnimationNode?
|
--- @field animationNode AnimationNode?
|
||||||
|
--- @field from love.Source
|
||||||
|
--- @field to love.Source
|
||||||
audio = {}
|
audio = {}
|
||||||
audio.__index = audio
|
audio.__index = audio
|
||||||
|
|
||||||
@ -17,10 +19,15 @@ local function new(musicVolume, soundVolume)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function audio:update(dt)
|
function audio:update(dt)
|
||||||
if self.animationNode then
|
if self.animationNode and self.animationNode.state == "running" then
|
||||||
self.animationNode:update(dt)
|
self.animationNode:update(dt)
|
||||||
print(self.animationNode.t)
|
self.from:setVolume(self.musicVolume - self.animationNode:getValue() * self.musicVolume)
|
||||||
print(self.animationNode:getValue())
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -32,64 +39,22 @@ end
|
|||||||
--- @param to love.Source
|
--- @param to love.Source
|
||||||
--- @param ms number? in milliseconds
|
--- @param ms number? in milliseconds
|
||||||
function audio:crossfade(from, to, ms)
|
function audio:crossfade(from, to, ms)
|
||||||
|
print("[Audio]: Triggered crossfade")
|
||||||
to:setVolume(0)
|
to:setVolume(0)
|
||||||
to:play()
|
to:play()
|
||||||
local fromVol = from:getVolume() or self.musicVolume
|
self.from = from
|
||||||
local toVol = to:getVolume() or self.musicVolume
|
self.to = to
|
||||||
local dt = love.timer.getDelta() * (ms or 1000)
|
|
||||||
|
|
||||||
while fromVol > 0 and toVol < self.musicVolume do
|
|
||||||
print(fromVol, toVol)
|
|
||||||
fromVol = self.musicVolume - fromVol + dt / self.musicVolume
|
|
||||||
from:setVolume(ease.easeOutQuad(fromVol))
|
|
||||||
toVol = toVol + dt / self.musicVolume
|
|
||||||
to:setVolume(ease.easeInQuad(toVol))
|
|
||||||
print(fromVol, toVol)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--- if from is nil, than we have fade in to;
|
|
||||||
--- if to is nil, than we have fade out from
|
|
||||||
---
|
|
||||||
--- also we should guarantee, that from and to have the same volume
|
|
||||||
--- @param from love.Source
|
|
||||||
--- @param to love.Source
|
|
||||||
--- @param ms number? in milliseconds
|
|
||||||
function audio:crossfadeAnim(from, to, ms)
|
|
||||||
to:setVolume(0)
|
|
||||||
to:play()
|
|
||||||
print(from:getVolume(), to:getVolume())
|
|
||||||
local t = 0
|
|
||||||
self.animationNode = AnimationNode {
|
self.animationNode = AnimationNode {
|
||||||
function(node)
|
function(node) end,
|
||||||
from:setVolume(self.musicVolume - node:getValue() * self.musicVolume)
|
|
||||||
to:setVolume(node:getValue() * self.musicVolume)
|
|
||||||
t = node.t
|
|
||||||
print(node.duration, node.t)
|
|
||||||
end,
|
|
||||||
onEnd = function()
|
onEnd = function()
|
||||||
from:setVolume(0)
|
self.from:setVolume(0)
|
||||||
to:setVolume(self.musicVolume)
|
self.to:setVolume(self.musicVolume)
|
||||||
|
print("[Audio]: Crossfade done")
|
||||||
end,
|
end,
|
||||||
duration = ms or 1000,
|
duration = ms or 1000,
|
||||||
easing = ease.linear,
|
easing = ease.easeOutCubic,
|
||||||
-- children = {
|
|
||||||
-- AnimationNode {
|
|
||||||
-- function(node)
|
|
||||||
-- from:setVolume(self.musicVolume - node:getValue() * self.musicVolume)
|
|
||||||
-- end
|
|
||||||
-- },
|
|
||||||
-- AnimationNode {
|
|
||||||
-- function(node)
|
|
||||||
-- to:setVolume(node:getValue() * self.musicVolume)
|
|
||||||
-- print(node.count)
|
|
||||||
-- end
|
|
||||||
-- }
|
|
||||||
-- }
|
|
||||||
}
|
}
|
||||||
self.animationNode:run()
|
self.animationNode:run()
|
||||||
-- anim:finish()
|
|
||||||
print(from:getVolume(), to:getVolume(), t, t, t)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @param source love.Source
|
--- @param source love.Source
|
||||||
|
|||||||
@ -92,8 +92,8 @@ function regenerateMana:cast(caster, target)
|
|||||||
function(node)
|
function(node)
|
||||||
local audioPath = Tree.assets.files.audio
|
local audioPath = Tree.assets.files.audio
|
||||||
sprite:animate("hurt", node)
|
sprite:animate("hurt", node)
|
||||||
Tree.audio:crossfadeAnim(audioPath.music.level1.battle,
|
Tree.audio:crossfade(audioPath.music.level1.battle,
|
||||||
audioPath.music.level1.choral, 2000)
|
audioPath.music.level1.choral, 5000)
|
||||||
end,
|
end,
|
||||||
onEnd = function() caster:has(Tree.behaviors.spellcaster):endCast() end
|
onEnd = function() caster:has(Tree.behaviors.spellcaster):endCast() end
|
||||||
}:run()
|
}:run()
|
||||||
|
|||||||
@ -13,7 +13,7 @@ Tree.audio = (require "lib.audio").new(1, 1)
|
|||||||
Tree.level = (require "lib.level.level").new("procedural", "flower_plains") -- для теста у нас только один уровень, который сразу же загружен
|
Tree.level = (require "lib.level.level").new("procedural", "flower_plains") -- для теста у нас только один уровень, который сразу же загружен
|
||||||
|
|
||||||
Tree.behaviors = (require "lib.utils.behavior_loader")("lib/character/behaviors") --- @todo написать нормальную загрузку поведений
|
Tree.behaviors = (require "lib.utils.behavior_loader")("lib/character/behaviors") --- @todo написать нормальную загрузку поведений
|
||||||
Tree.audio = (require "lib.audio").new(1, 1)
|
-- Tree.audio = (require "lib.audio").new(1, 1)
|
||||||
-- Tree.behaviors.map = require "lib.character.behaviors.map"
|
-- Tree.behaviors.map = require "lib.character.behaviors.map"
|
||||||
-- Tree.behaviors.spellcaster = require "lib.character.behaviors.spellcaster"
|
-- Tree.behaviors.spellcaster = require "lib.character.behaviors.spellcaster"
|
||||||
-- Tree.behaviors.sprite = require "lib.character.behaviors.sprite"
|
-- Tree.behaviors.sprite = require "lib.character.behaviors.sprite"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user