From ae03ee3adb9737794a43b4dc8981720cd593784a Mon Sep 17 00:00:00 2001 From: neckrat Date: Sun, 18 Jan 2026 13:32:45 +0300 Subject: [PATCH] add looping to music --- lib/audio.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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