ecspresso
    Preparing search index...

    Interface AudioHelpers<W>

    Typed helpers for the audio plugin. Creates helpers that validate sound keys and channel names against the world type W. Call after .build() using typeof ecs.

    const ecs = ECSpresso.create()
    .withPlugin(createAudioPlugin({ channels }))
    .withAssets(a => a.add('boom', loadSound('/sfx/boom.mp3')))
    .build();

    const { createAudioSource } = createAudioHelpers<typeof ecs>();
    // Type-safe: 'boom' must be a registered asset, 'sfx' a valid channel
    createAudioSource('boom', 'sfx');
    interface AudioHelpers<W extends AnyECSpresso> {
        createAudioSource: (
            sound: keyof AssetsOfWorld<W> & string,
            channel: ChannelOfWorld<W>,
            options?: { autoRemove?: boolean; loop?: boolean; volume?: number },
        ) => Pick<AudioComponentTypes<ChannelOfWorld<W>>, "audioSource">;
    }

    Type Parameters

    • W extends AnyECSpresso

      Concrete ECS world type (e.g. typeof ecs)

    Index

    Properties

    createAudioSource: (
        sound: keyof AssetsOfWorld<W> & string,
        channel: ChannelOfWorld<W>,
        options?: { autoRemove?: boolean; loop?: boolean; volume?: number },
    ) => Pick<AudioComponentTypes<ChannelOfWorld<W>>, "audioSource">