Skip to content

Instantly share code, notes, and snippets.

@hazzard993
Created April 11, 2019 06:58
Show Gist options
  • Save hazzard993/40e969a37381a81346ae4a2e845d66a7 to your computer and use it in GitHub Desktop.
Save hazzard993/40e969a37381a81346ae4a2e845d66a7 to your computer and use it in GitHub Desktop.

Effect Registry

LÖVE 2D allows Effects to be added to the audio that is playing. Each effect is added with a name which can be used to obtain the audio effect later.

love.audio.setEffect("myEffect", {...});
love.audio.getEffect("myEffect");

To aid TypeScript, an EffectRegistry interface has been provided to keep track of the audio effects planned to be set.

You can re-declare this interface to tell TypeScript what effects you plan to set, this can be done in an EffectRegistry.d.ts file.

interface EffectRegistry {
    myEffect: ChorusEffectSettings;
}

The example above will tell TypeScript that myEffect is the only effect available so it will prevent you from using get/setEffect with the name of an effect not in the registry.

// No. Only effects from the registry allowed.
// Add myEffect2 to the registry or fix the name.
love.audio.setEffect("myEffect2", {...});

// myEffect2 will not exist.
love.audio.getEffect("myEffect2");

// This exists, and I also know the type of effect.
love.audio.getEffect("myEffect");

It also tells TypeScript what kind of an effect this is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment