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) or while the sound is played in a loop.

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 careful 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, loop?: boolean, players?: PlayerPermission): 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

    • Optional loop: boolean

      If true, play the sound again from the beginning once it finishes playing. You can stop playback using stop, stopLoop, or by calling a play method with the loop parameter set to false.

    • Optional players: PlayerPermission

      Determines for which players the sound will be played. By default, it will be played for all players

    Returns void

playAtLocation

  • playAtLocation(position: Vector | [x: number, y: number, z: number], startTime?: number, volume?: number, loop?: boolean, players?: PlayerPermission): 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 | [x: number, y: number, z: number]

      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

    • Optional loop: boolean

      If true, play the sound again from the beginning once it finishes playing. You can stop playback using stop, stopLoop, or by calling a play method with the loop parameter set to false.

    • Optional players: PlayerPermission

      Determines for which players the sound will be played. By default, it will be played for all players

    Returns void

playAttached

  • 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

    • Optional loop: boolean

      If true, play the sound again from the beginning once it finishes playing. You can stop playback using stop, stopLoop, or by calling a play method with the loop parameter set to false.

    • Optional players: PlayerPermission

      Determines for which players the sound will be played. By default, it will be played for all players

    Returns void

stop

  • stop(): void
  • Stop playing the sound immediately

    Returns void

stopLoop

  • stopLoop(): void
  • Stop looping the sound if it is currently played in a loop. Doesn't stop playback immediately, only after the current playback finishes. Has no effect if the sound is not currently played in a loop.

    Returns void