diff --git a/lib/audio.lua b/lib/audio.lua index 5057f30..3e7d44c 100644 --- a/lib/audio.lua +++ b/lib/audio.lua @@ -4,9 +4,10 @@ local AnimationNode = require "lib.animation_node" --- @class Audio --- @field musicVolume number --- @field soundVolume number +--- @field looped boolean --- @field animationNode AnimationNode? ---- @field from love.Source ---- @field to love.Source +--- @field from love.Source? +--- @field to love.Source? audio = {} audio.__index = audio @@ -14,7 +15,8 @@ audio.__index = audio local function new(musicVolume, soundVolume) return setmetatable({ musicVolume = musicVolume, - soundVolume = soundVolume + soundVolume = soundVolume, + looped = true }, audio) end @@ -40,8 +42,8 @@ end --- @param ms number? in milliseconds function audio:crossfade(from, to, ms) print("[Audio]: Triggered crossfade") + self:play(to) to:setVolume(0) - to:play() self.from = from self.to = to self.animationNode = AnimationNode { @@ -60,6 +62,7 @@ end --- @param source love.Source function audio:play(source) if source:getType() == "stream" then + source:setLooping(self.looped) source:setVolume(self.musicVolume) return source:play() end