Jump to content

SetFilter only works once per speaker.


Go to solution Solved by Josh,

Recommended Posts

Posted
#include "Leadwerks.h"

using namespace Leadwerks;

int main(int argc, const char* argv[])
{
    //Get the displays
    auto displays = GetDisplays();

    //Create a window
    auto window = CreateWindow("Leadwerks", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);

    //Create a world
    auto world = CreateWorld();

    //Create a framebuffer
    auto framebuffer = CreateFramebuffer(window);

    //Create a camera
    auto camera = CreateCamera(world);
    camera->SetClearColor(0.125);
    camera->SetFov(70);
    camera->SetPosition(0, 0, -3);
    camera->Listen();

    //Create a light
    auto light = CreateBoxLight(world);
    light->SetRotation(35, 45, 0);
    light->SetRange(-10, 10);

    //Create a box
    auto box = CreateBox(world);
    box->SetColor(0, 0, 1);

    //Sound
    auto sound = LoadSound("https://raw.githubusercontent.com/Leadwerks/Documentation/master/Assets/Sound/notification.wav");
    auto speaker = CreateSpeaker(sound);
    speaker->SetLooping(true);
    speaker->SetPosition(box->GetPosition(true));
    speaker->Play();
    speaker->SetRange(10);

    //Main loop
    bool swapped = false;
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {

        //Add filter when space key is pressed
        if (window->KeyHit(KEY_SPACE))
        {
            swapped = not swapped;
            if (swapped)
                speaker->SetFilter(AUDIOFILTER_REVERB_SEWERPIPE);
            else
                speaker->SetFilter(AUDIOFILTER_NONE);
        }

        //Move and turn with the arrow keys - best experienced with headphones
        if (window->KeyDown(KEY_UP)) camera->Move(0, 0, 0.1);
        if (window->KeyDown(KEY_DOWN)) camera->Move(0, 0, -0.1);
        if (window->KeyDown(KEY_LEFT)) camera->Turn(0, -1, 0);
        if (window->KeyDown(KEY_RIGHT)) camera->Turn(0, 1, -0);

        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

It'll work the first time, then it'll work when you go to set it back to none. However, when you try it again, it doesn't work.

  • Like 1

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...