SetPosition

This function sets a source's position in global space.

Syntax

Parameters

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;
Vec3 position = Vec3(0, 0, 1);

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();

//Create a listener
Listener* listener = Listener::Create();

while (true)
{
//Press left/right keys to move the source
if (window->KeyDown(Key::Right)) position.x += Leadwerks::Time::GetSpeed()*0.1;
if (window->KeyDown(Key::Left)) position.x -= Leadwerks::Time::GetSpeed()*0.1;

source->SetPosition(position);

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("Position: " + position.ToString(), 2, 2);

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