SetVolume

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

Syntax

Parameters

Example

#include "Leadwerks.h"

using namespace Leadwerks;
Source* source = NULL;
float volume = 0.5;

int main(int argc, const char *argv[])
{
Leadwerks::Window* window = Leadwerks::Window::Create();
Context* context = Context::Create(window);
//Load a sound
Sound* 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)
{
//Press space key to go back to the start of the soud
if (window->KeyDown(Key::Up)) volume += Leadwerks::Time::GetSpeed() * 0.01;
if (window->KeyDown(Key::Down)) volume -= Leadwerks::Time::GetSpeed() * 0.01;
volume = Math::Clamp(volume,0,1);

source->SetVolume(volume);

if (window->Closed() || window->KeyDown(Key::Escape)) return false;
Leadwerks::Time::Update();
context->SetColor(0,0,0,0);
context->Clear();

context->SetColor(1,1,1,0);
context->SetBlendMode(Blend::Alpha);
context->DrawText("Volume: "+String(volume),2,2);

context->Sync();
}
return 0;
}