Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Sound

Sound that is played in DX Engine.

All sounds require a sound asset id and need to be fully loaded before they can be played.

Hierarchy

  • Sound

Implements

Index

Constructors

Properties

currentPosition: number

Defines the track position of this Sound.

duration: number

Returns duration of this Sound in seconds.

playSpeed: number

Defines the local playback speed of this Sound.

playSpeedIndependent: boolean

Toggles use of local playback speed modifier of this Sound.

If true, this Sound uses local playback speed.

volume: number

Defines the normalized volume of this Sound. Volume value is clamped to range [0,1]

playSpeedMultiplier: number

Defines the playback speed of all sounds played in the Scene.

param speed

playback speed

Methods

  • dispose(): void
  • Disposes this object, effectively turning this into an unmanaged resource.

    Returns void

  • isPlaying(): boolean
  • Returns true if the sound is currently playing

    Returns boolean

  • pause(): void
  • Pauses playback of this Sound.

    The sound resumes at the same track position with next play call.

    Returns void

  • play(): void
  • play(onFinish: (() => void)): void
  • play(looping: boolean): void
  • Plays this Sound.

    If the sound is not fully loaded, the playback will delay until loading is complete.

    Returns void

  • Plays this Sound.

    If the sound is not fully loaded, the playback will delay until loading is complete.

    Parameters

    • onFinish: (() => void)

      callback function when the Sound finishes.

        • (): void
        • Returns void

    Returns void

  • Plays this Sound.

    If the sound is not fully loaded, the playback will delay until loading is complete.

    Parameters

    • looping: boolean

      if true, this Sound loops indefinitely.

    Returns void

  • stop(): void
  • Stops playback of this Sound.

    The sound starts from the beginning with next play call.

    Returns void

  • load(id: string): Sound
  • load(id: string, callback: ((t: Sound) => void)): Sound
  • Loads a sound via the provided sound id.

    Parameters

    • id: string

      sound asset id.

    Returns Sound

    loaded Sound.

  • Loads a sound via the provided sound id.

    Parameters

    • id: string

      sound asset id.

    • callback: ((t: Sound) => void)

      triggers once the Sound is fully loaded.

    Returns Sound

    loaded Sound.

  • playOneShot(sound: Sound, volume: number): void
  • Plays a oneshot sound based on the provided, loaded Sound.

    Oneshot sounds can be played multiple times from the same Sound source and are useful for repeating sound effects like rain and foot steps.

    Parameters

    • sound: Sound

      sound to play once.

    • volume: number

      normalized volume at which to play the sound.

    Returns void

  • stopAll(): void
  • Stops all sounds that are currently playing.

    Returns void

  • stopById(soundIds: Iterable<string>): void
  • stopById(soundId: string): void
  • Stops all sounds by their sound asset id.

    Parameters

    • soundIds: Iterable<string>

      array of sound asset ids.

    Returns void

  • Stops a sound by its sound asset id.

    Parameters

    • soundId: string

      array of sound asset ids.

    Returns void