SetVolume

This function will set a source's volume. The default volume is 1.0.

Syntax

Parameters

Example

volume = .5

--Create a window
window = Window:Create()
context = Context:Create(window)

--Load a sound
local sound = Sound:Load("Sound/Music/menutheme.wav")

--Create a source
source = Source:Create()
source:SetSound(sound)
sound:Release()
source:SetLoopMode(true)
source:SetVolume(volume)
source:Play()

while true do
--Press space key to go back to the start of the soud
if (window:KeyDown(Key.Up))then volume = volume + Time:GetSpeed() * 0.01 end
if (window:KeyDown(Key.Down))then volume = volume - Time:GetSpeed() * 0.01 end
volume = Math:Clamp(volume,0,1)

source:SetVolume(volume)

if window:Closed() or window:KeyHit(Key.Escape) then return false end

Time:Update()
context:SetColor(0,0,0)
context:Clear()

context:SetColor(1,1,1)
context:SetBlendMode(Blend.Alpha)
context:DrawText("Volume: "..volume,2,2)

context:Sync()

end