Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Sound

A sound that can be played. Create Sound objects by importing sound files using GameWorld.importSound or GameWorld.importSoundFromURL.

Hierarchy

  • Sound

Index

Properties

onLoadComplete

onLoadComplete: Delegate<(success: boolean) => void>

Called when the sound has finished or failed to load.

param

True when the sound has loaded successfully and can be played, false if it has failed to load

onPlaybackFinished

onPlaybackFinished: Delegate<() => void>

Called when playback of the sound has finished. Not called when the sound is interrupted (for example by calling stop)

Methods

destroy

  • destroy(): void
  • Destroy this sound and free its resources. Call this function when you don't need a loaded sound anymore. The object will become non-functional, and it will be removed from the cache. Note that multiple calls to GameWorld.importSound or GameWorld.importSoundFromURL with the same parameters return the same object when using caching, so if you use the same sound at multiple places in your code, you should be carefuly when you destroy it.

    Returns void

getDuration

  • getDuration(): number
  • Return the duration of the sound in seconds. Will be 0 if the sound is not loaded.

    Returns number

getPlaybackFraction

  • getPlaybackFraction(): number
  • Return the current playback time of the sound as a fraction of its duration. Will be 0 if the sound is not playing.

    Returns number

getPlaybackTime

  • getPlaybackTime(): number
  • Return the current playback time of the sound in seconds. Will be 0 if the sound is not playing.

    Returns number

isLoaded

  • isLoaded(): boolean
  • Return whether the sound has finished loading successfully and is ready to play

    Returns boolean

isPlaying

  • isPlaying(): boolean
  • Return whether the sound is currently playing

    Returns boolean

play

  • play(startTime?: number, volume?: number): void
  • Start playing the sound. It will not appear to come from any location. If it is already playing, the playback time will be moved. If the sound isn't loaded yet when this method is called, the sound will be played as soon as loading has finished.

    Parameters

    • Optional startTime: number

      The starting playback time. Set to 0 to play from the beginning. Default: 0

    • Optional volume: number

      The volume multiplier at which to play the sound, 0 < volume < 2. Default: 1

    Returns void

playAtLocation

  • playAtLocation(position: Vector, startTime?: number, volume?: number): void
  • Start playing the sound at a given position. If it is already playing, the playback time will be moved. If the sound isn't loaded yet when this method is called, the sound will be played as soon as loading has finished.

    Parameters

    • position: Vector

      The position where the sound should originate.

    • Optional startTime: number

      The starting playback time. Set to 0 to play from the beginning. Default: 0

    • Optional volume: number

      The volume multiplier at which to play the sound, 0 < volume < 2. Default: 1

    Returns void

playAttached

  • playAttached(object: GameObject, startTime?: number, volume?: number): void
  • Start playing the sound at the location of an object. It will move together with the object. If the sound is already playing, the playback time will be moved. If the sound isn't loaded yet when this method is called, the sound will be played as soon as loading has finished.

    Parameters

    • object: GameObject

      The object from which the sound should originate.

    • Optional startTime: number

      The starting playback time. Set to 0 to play from the beginning. Default: 0

    • Optional volume: number

      The volume multiplier at which to play the sound, 0 < volume < 2. Default: 1

    Returns void

stop

  • stop(): void