new Sound()
A Sound Component is responsible for playing sounds.
Name | Type | Default | Description |
---|---|---|---|
name | string | Name of the sound. | |
src | string | Path to the sound file. | |
volume | number | 1 | Volume of the sound. |
loop | boolean | false | If the sound should loop. |
- Source
// 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.
- boolean
- Source
(protected) name :string
Name of the sound. Names are not processed by the engine. Can be used for referencing the sound.
- string
- Source
(protected, readonly) playing :boolean
Check if the sound is playing.
- boolean
- Source
(readonly) properties
The entity that this component is attached to.
- Inherited From
- Source
(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.
- string
- Source
(protected) volume :number
Volume of the sound. The volume should be between 0 and 1.
- number
- Source
Methods
Pause()
Pause a playing sound. If the sound is not playing, this will do nothing.
- Source
Play()
Play the sound. If the sound is already playing, it will be stopped and played again.
- Source
Stop()
Stop the sound. If the sound is not playing, this will do nothing.
- Source