dacha
    Preparing search index...

    Class AudioSource

    AudioSource component for playing audio.

    It handles the playing of audio for an actor. It allows to play audio files and control the volume and looping of the audio.

    // Create an audio source
    const audioSource = new AudioSource({
    src: 'assets/audio/some-sound.mp3',
    group: 'master',
    looped: false,
    volume: 1,
    autoplay: false,
    });

    // Add to actor
    actor.setComponent(audioSource);

    // Modify properties
    audioSource.volume = 0.5; // Set volume to 50%

    // Play the audio (restarts it from the beginning if it's already playing)
    audioSource.play();

    // Play it, but leave an already-playing instance alone instead of
    // restarting it
    audioSource.play(false);

    // Stop the audio
    audioSource.stop();

    Hierarchy (View Summary)

    Index
    _playing: boolean

    Whether the audio is currently playing

    _restarting: boolean

    Whether a still-playing sound should restart from the beginning

    actor?: Actor
    autoplay: boolean

    Whether the audio is autoplayed on scene enter or after actor is added to scene

    group: string

    Group of the audio, used to combine audio sources together and control them at once

    looped: boolean

    Whether the audio is looped

    src: string

    Path to the audio asset

    volume: number

    Volume of the audio, from 0 to 1

    componentName: string
    • Starts playback.

      If the sound is already playing, it restarts from the beginning by default; pass restart: false to leave an already-playing instance untouched instead.

      Parameters

      • restart: boolean = true

        Whether to restart the sound if it's already playing. Defaults to true.

      Returns void

    • Stops playback.

      Returns void