Hi,
Does anyone know if it is possible to use tween.lua to fade out audio using love.audio.setVolume? The tween.lua github page says the target must be a table, so I feel like I might be out of luck since setVolume is a function. I'm not sure if I can pass the target into tween.lua in any way.
tween.lua and love.audio.setVolume
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Roland_Yonaba
- Inner party member
- Posts: 1563
- Joined: Tue Jun 21, 2011 6:08 pm
- Location: Ouagadougou (Burkina Faso)
- Contact:
Re: tween.lua and love.audio.setVolume
Just a random idea.
Create a tween object that changes gradually the volume level from a value to another (Here, from 0 to 1).
Then, in love.update, use this :
This just popped in my head, I haven't tried it. I don't know if calling love.audio.setVolume repetively every dt is advised, so I'll let people provide some feedback.
Create a tween object that changes gradually the volume level from a value to another (Here, from 0 to 1).
Code: Select all
local volume = {level = 0}
local volumeTweener = tween.new(duration, volume, {level = 1}, easingFunction)
Code: Select all
function love.update(dt)
-- some code
volumeTweener:update(dt)
love.audio.setVolume(volume.level)
-- rest of the code
end
Re: tween.lua and love.audio.setVolume
This is what I always do, and it works perfectly.Roland_Yonaba wrote:Just a random idea.
Though I don't know if it affects performance.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: tween.lua and love.audio.setVolume
It's a bit awkward, but metatables can do this too!
You don't even need to keep a reference to the 'volume' table.
Code: Select all
local volume = setmetatable({}, {
__index = function() return 0 end, -- the initial value
__newindex = function(self, k, v) return love.audio.setVolume(v) end,
})
local volumeTweener = tween.new(duration, volume, {volume = 1}, easingFunction)
- Roland_Yonaba
- Inner party member
- Posts: 1563
- Joined: Tue Jun 21, 2011 6:08 pm
- Location: Ouagadougou (Burkina Faso)
- Contact:
Re: tween.lua and love.audio.setVolume
Lövely, Bartbes.bartbes wrote:It's a bit awkward, but metatables can do this too!
You don't even need to keep a reference to the 'volume' table.Code: Select all
local volume = setmetatable({}, { __index = function() return 0 end, -- the initial value __newindex = function(self, k, v) return love.audio.setVolume(v) end, }) local volumeTweener = tween.new(duration, volume, {volume = 1}, easingFunction)
You have been blissed.
Re: tween.lua and love.audio.setVolume
Thank you so much, everyone!
I ended up using Roland_Yonaba's suggestion since it looked a little cleaner than the metatables (which also just scare me right now, haha). Seems like it works perfectly!
I ended up using Roland_Yonaba's suggestion since it looked a little cleaner than the metatables (which also just scare me right now, haha). Seems like it works perfectly!
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 4 guests