Skip to main content

removeSpriteConfig

Clear the sprite config recorded on a sound. After this, getSpriteConfig returns undefined for it.

removeSpriteConfig(id: string): void;

Parameters​

ParameterTypeDefaultDescription
idstringrequiredID of the sound the sprites were set on.

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], fail: [6, 8.5] });

// Take the sprite sounds away first, while the keys can still be resolved
soundHub.removeSpriteSound('jump');
soundHub.removeSpriteSound('fail');

soundHub.removeSpriteConfig('game-sounds');
soundHub.getSpriteConfig('game-sounds'); // undefined

Good to know​

  • Only the record is cleared. The sprite sounds that setSoundSprite created stay in the hub, so playSprite('game-sounds', 'jump') still plays.
  • Afterwards removeSpriteSound can no longer find those sprites by key. Pass the full sprite id instead, such as 'game-sounds_jump', or remove the sprites before you clear the config, as in the example.
  • No event is dispatched. For an id that is not loaded, the error is logged, stored for getLastError and dispatched as an error event.

See also​