SetRange
This function sets the audible range of a sound source.
Syntax
- void SetRange(float range)
Parameters
- range: the range beyond which the source will be inaudible.
Remarks
Only sounds in mono format can be played with 3D spatialization. Stereo sounds will not be affected.
Example
#include "Leadwerks.h"
using namespace Leadwerks;
Source* source = NULL;
float range = 1.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");
source = Source::Create();
source->SetSound(sound);
source->SetLoopMode(true);
source->Play();
source->SetPosition(Vec3(0, 0, 1));
//Create a listener
Listener* listener = Listener::Create();
listener->SetPosition(0, 0, 0);
while (true)
{
//Press up/down keys to adjust the source range
if (window->KeyDown(Key::Up)) range += Leadwerks::Time::GetSpeed()*0.1;
if (window->KeyDown(Key::Down)) range -= Leadwerks::Time::GetSpeed()*0.1;
if (range < 0) range = 0;
source->SetRange(range);
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("Range: " + String(range), 2, 2);
context->Sync();
}
return 0;
}