const channels = defineAudioChannels({
sfx: { volume: 1 },
music: { volume: 0.7 },
});
const ecs = ECSpresso.create()
.withAssets(a => a.add('explosion', loadSound('/sfx/boom.mp3')))
.withPlugin(createAudioPlugin({ channels }))
.build();
await ecs.initialize();
const audio = ecs.getResource('audioState');
audio.play('explosion', { channel: 'sfx' });
Create an audio plugin for ECSpresso.
Provides:
audioStateresource for fire-and-forget SFX and musicaudioSourcecomponent for entity-attached soundsplaySound/stopMusicevent handlerssoundEndedevent on completionSounds must be preloaded through the asset pipeline (
loadSoundhelper).