Skip to main content

removeSpriteSound

Remove a sprite: its sound, every playing instance of it, and its key in the config. Use it when an effect is no longer needed and you want its buffer and nodes gone.

removeSpriteSound(spriteKey: string): void;

Parameters​

ParameterTypeDefaultDescription
spriteKeystringrequiredA sprite key such as 'jump', or a full sprite id such as 'game-sounds_jump'.

Returns​

Nothing.

Example​

import { SoundHub } from 'soundhub';

const soundHub = new SoundHub();
await soundHub.loadSound('game-sounds', '/audio/8-bit-game-sounds.mp3');

soundHub.setSoundSprite('game-sounds', { jump: [4.5, 5.5], danger: [16.5, 18.5] });
soundHub.playSprite('game-sounds', 'danger', { loop: true });

// Stops the looping 'danger' sprite and removes it
soundHub.removeSpriteSound('danger');

soundHub.getSpriteConfig('game-sounds'); // { jump: [4.5, 5.5] }

Good to know​

  • There is no sound id parameter. A bare key is looked up in the config of every loaded sound, so removeSpriteSound('jump') removes the jump sprite of each sound that has one. Pass the full id, such as 'game-sounds_jump', to reach just one.
  • A key matches exactly: 'jump' leaves a double_jump sprite alone.
  • Playing or paused instances are stopped, taken off the master and dropped from any sound group they were in. Since 6.3.2 the key also leaves the config and the sprite's gain node is disconnected.
  • When nothing matches, it does nothing apart from a debug log. No event is dispatched.
  • A key is found through the config, so after removeSpriteConfig only the full sprite id still works.

See also​