gameforge - v0.1.12
    Preparing search index...

    Class Sound

    Sound represents a single piece of loaded media. When playing a sound IMediaInstance objects are created. Properties such a volume, pause, mute, speed, etc will have an effect on all instances.

    Index

    Properties

    autoPlay: boolean

    true to start playing immediate after load.

    false
    @readonly
    isLoaded: boolean

    true if the buffer is loaded.

    false
    
    isPlaying: boolean

    true if the sound is currently being played.

    false
    @readonly
    media: IMedia

    The audio source

    options: Options

    The constructor options.

    preload: boolean

    true to immediately start preloading.

    false
    @readonly
    singleInstance: boolean

    true to disallow playing multiple layered instances at once.

    false
    
    url: string

    The file source to load.

    Accessors

    • get context(): IMediaContext

      Instance of the media context.

      Returns IMediaContext

    • get duration(): number

      Get the duration of the audio in seconds.

      Returns number

    • get filters(): PixiSound.Filter[]

      Set the filters. Only supported with WebAudio.

      Returns PixiSound.Filter[]

    • set filters(filters: PixiSound.Filter[]): void

      Parameters

      Returns void

    • get instances(): IMediaInstance[]

      Gets the list of instances that are currently being played of this sound.

      Returns IMediaInstance[]

    • get isPlayable(): boolean

      If the current sound is playable (loaded).

      Returns boolean

    • get loop(): boolean

      Gets and sets the looping.

      Returns boolean

    • set loop(loop: boolean): void

      Parameters

      • loop: boolean

      Returns void

    • get muted(): boolean

      Gets and sets the muted flag.

      Returns boolean

    • set muted(muted: boolean): void

      Parameters

      • muted: boolean

      Returns void

    • get paused(): boolean

      Stops all the instances of this sound from playing.

      Returns boolean

    • set paused(paused: boolean): void

      Parameters

      • paused: boolean

      Returns void

    • get speed(): number

      The playback rate.

      Returns number

    • set speed(speed: number): void

      Parameters

      • speed: number

      Returns void

    • get sprites(): SoundSprites

      Get the map of sprites.

      Returns SoundSprites

    • get volume(): number

      Gets and sets the volume.

      Returns number

    • set volume(volume: number): void

      Parameters

      • volume: number

      Returns void

    Methods

    • Add a sound sprite, which is a saved instance of a longer sound. Similar to an image spritesheet.

      Parameters

      • alias: string

        The unique name of the sound sprite.

      • data: SoundSpriteData

        Either completed function or play options.

      Returns SoundSprite

    • Convenience method to add more than one sprite add a time.

      Parameters

      • data: SoundSpriteDataMap

        Map of sounds to add where the key is the alias, and the data are configuration options.

      Returns SoundSprites

      The map of sound sprites added.

    • Destructor, safer to use SoundLibrary.remove(alias) to remove this sound.

      Returns void

    • Stops all the instances of this sound from playing.

      Returns this

    • Play a sound sprite, which is a saved instance of a longer sound. Similar to an image spritesheet.

      Parameters

      • alias: string

        The unique name of the sound sprite.

      • Optionalcallback: CompleteCallback

        Callback when completed.

      Returns IMediaInstance | Promise<IMediaInstance>

      The sound instance, this cannot be reused after it is done playing. Returns a Promise if the sound has not yet loaded.

      play

    • Plays the sound.

      Parameters

      • Optionalsource: string | CompleteCallback | PlayOptions

        Either completed function or play options.

      • Optionalcallback: CompleteCallback

        Callback when completed.

      Returns IMediaInstance | Promise<IMediaInstance>

      The sound instance, this cannot be reused after it is done playing. Returns a Promise if the sound has not yet loaded.

      play

    • Internal only, speed, loop, volume change occured.

      Returns void

    • Handle changes in paused state. Internal only.

      Returns void

    • Remove a sound sprite.

      Parameters

      • Optionalalias: string

        The unique name of the sound sprite, if alias is omitted, removes all sprites.

      Returns Sound

    • Resuming all the instances of this sound from playing

      Returns this

    • Stops all the instances of this sound from playing.

      Returns this

    • Create a new sound instance from source.

      Parameters

      • source: string | ArrayBuffer | string[] | Options | HTMLAudioElement | AudioBuffer

        Either the path or url to the source file. or the object of options to use.

      Returns Sound

      Created sound instance.