feature/audioengine #26
@ -4,6 +4,7 @@ local AnimationNode = require "lib.animation_node"
|
||||
--- @class Audio
|
||||
--- @field musicVolume number
|
||||
--- @field soundVolume number
|
||||
--- @field animationNode AnimationNode?
|
||||
audio = {}
|
||||
audio.__index = audio
|
||||
|
||||
@ -15,6 +16,13 @@ local function new(musicVolume, soundVolume)
|
||||
}, audio)
|
||||
end
|
||||
|
||||
function audio:update(dt)
|
||||
if self.animationNode then
|
||||
self.animationNode:update(dt)
|
||||
print(self.animationNode.t)
|
||||
print(self.animationNode:getValue())
|
||||
end
|
||||
end
|
||||
|
||||
--- if from is nil, than we have fade in to;
|
||||
--- if to is nil, than we have fade out from
|
||||
@ -22,7 +30,7 @@ end
|
||||
--- 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
|
||||
--- @param ms number? in milliseconds
|
||||
function audio:crossfade(from, to, ms)
|
||||
to:setVolume(0)
|
||||
to:play()
|
||||
@ -46,13 +54,13 @@ end
|
||||
--- 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
|
||||
--- @param ms number? in milliseconds
|
||||
function audio:crossfadeAnim(from, to, ms)
|
||||
to:setVolume(0)
|
||||
to:play()
|
||||
print(from:getVolume(), to:getVolume())
|
||||
local t = 0
|
||||
local anim = AnimationNode {
|
||||
self.animationNode = AnimationNode {
|
||||
function(node)
|
||||
from:setVolume(self.musicVolume - node:getValue() * self.musicVolume)
|
||||
to:setVolume(node:getValue() * self.musicVolume)
|
||||
@ -79,8 +87,8 @@ function audio:crossfadeAnim(from, to, ms)
|
||||
-- }
|
||||
-- }
|
||||
}
|
||||
anim:run()
|
||||
anim:finish()
|
||||
self.animationNode:run()
|
||||
-- anim:finish()
|
||||
print(from:getVolume(), to:getVolume(), t, t, t)
|
||||
end
|
||||
|
||||
|
||||
@ -51,7 +51,9 @@ function walk:cast(caster, target)
|
||||
local sprite = caster:has(Tree.behaviors.sprite)
|
||||
if not sprite then return true end
|
||||
AnimationNode {
|
||||
function(node) caster:has(Tree.behaviors.map):followPath(path, node) end,
|
||||
function(node)
|
||||
caster:has(Tree.behaviors.map):followPath(path, node)
|
||||
end,
|
||||
onEnd = function() caster:has(Tree.behaviors.spellcaster):endCast() end,
|
||||
}:run()
|
||||
|
||||
@ -91,7 +93,7 @@ function regenerateMana:cast(caster, target)
|
||||
local audioPath = Tree.assets.files.audio
|
||||
sprite:animate("hurt", node)
|
||||
Tree.audio:crossfadeAnim(audioPath.music.level1.battle,
|
||||
audioPath.music.level1.choral, 3000)
|
||||
audioPath.music.level1.choral, 2000)
|
||||
end,
|
||||
onEnd = function() caster:has(Tree.behaviors.spellcaster):endCast() end
|
||||
}:run()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user