Sound:FadeIn(time) and Sound:FadeOut(time)

Could be used to smoothly tween a sound’s volume in or out over a specified time. Even though this can already be achieved fairly easily with loops, I feel like it’s a common enough occurrence to deserve its own function.

15 Likes

It could be added as new parameters to Sound:Play() and Sound:Stop() (that, and SoundService:PlayLocalSound) - seeing as the use is closely tied to playing/stopping the audio.

void Sound:Play([number fadeTime = 0])
void Sound:Stop([number fadeTime = 0])
void SoundService:PlayLocalSound(Sound sound[, number fadeTime = 0])
3 Likes

There shouldn’t be any tweening methods. There should just be a generic global tweening function.

5 Likes

I’ve found that having a modulescript for tweening is pretty useful, after seeing other developers (Acecateer IIRC) having such a thing.

TweenUtility.rbxmx (14.4 KB)

Example of use:

local tweenUtil = require(ModuleScript)

tweenUtil.tween(Sound, "Volume", 1, "In", "Quad", 2, function(status)
    print("The tween was:", status.Name) -- can be Completed or Cancelled
end)

local parts = {
    [workspace.Part1] = workspace.Part1.CFrame,
    [workspace.Part2] = workspace.Part2.CFrame,
    [workspace.Abc] = workspace.Abc.CFrame
}
tweenUtil.tweenFunc(function(progress)
    for part, partCFrame in next, parts do
        part.Size = Vector3.new(progress, progress, progress) * 5
        part.CFrame = partCFrame
    end
end, Enum.EasingDirection.Out, Enum.EasingStyle.Bounce, 1)

But it’d be great to have a dedicated API for tweening as Sharksie suggests, yeah.

I’d prefer something like this to be implemented in lua.

Heck, I’d even prefer that it be in open source lua, so that I could add whatever functionality I’d need in the future (like interrupts, kill-alls, etc).

I’d prefer a discrete set of sound operations that work independently of Lua threads so that timing can be exact.