add looping to music
This commit is contained in:
parent
2c8b65e1ae
commit
ae03ee3adb
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user