Sound

new Sound()

A Sound Component is responsible for playing sounds.

Properties
NameTypeDefaultDescription
namestring

Name of the sound.

srcstring

Path to the sound file.

volumenumber1

Volume of the sound.

loopbooleanfalse

If the sound should loop.

Example
// Create a sound component
let sound = new Sound("Jump", "assets/sounds/jump.wav");

// Add the sound component to an entity
entity.AddComponent(sound);

// Play the sound
sound.Play();

Extends

Members

(protected) loop :boolean

Loop the sound.

Type:
  • boolean

(protected) name :string

Name of the sound. Names are not processed by the engine. Can be used for referencing the sound.

Type:
  • string

(protected, readonly) playing :boolean

Check if the sound is playing.

Type:
  • boolean

(readonly) properties

The entity that this component is attached to.

Inherited From

(protected) src :string

Source path of the sound. This is the path to the sound file. Note: While hosting on a server, the path should be relative to the root directory.

Type:
  • string

(protected) volume :number

Volume of the sound. The volume should be between 0 and 1.

Type:
  • number

Methods

Pause()

Pause a playing sound. If the sound is not playing, this will do nothing.

Play()

Play the sound. If the sound is already playing, it will be stopped and played again.

Stop()

Stop the sound. If the sound is not playing, this will do nothing.