Constructor
new SoundComponent(system, entity)
Create a new Sound Component.
Parameters:
Name | Type | Description |
---|---|---|
system |
pc.SoundComponentSystem | The ComponentSystem that created this Component |
entity |
pc.Entity | The entity that the Component is attached to |
Properties:
Name | Type | Description |
---|---|---|
volume |
Number | The volume modifier to play the audio with. In range 0-1. |
pitch |
Number | The pitch modifier to play the audio with. Must be larger than 0.01 |
positional |
Boolean | If true the audio will play back at the location of the Entity in space, so the audio will be affect by the position of the pc.AudioListenerComponent. |
distanceModel |
String | Determines which algorithm to use to reduce the volume of the sound as it moves away from the listener. Can be one of pc.DISTANCE_LINEAR, pc.DISTANCE_INVERSE or pc.DISTANCE_EXPONENTIAL. Default is pc.DISTANCE_LINEAR. |
refDistance |
Number | The reference distance for reducing volume as the sound source moves further from the listener. |
maxDistance |
Number | The maximum distance from the listener at which audio falloff stops. Note the volume of the audio is not 0 after this distance, but just doesn't fall off anymore. |
rollOffFactor |
Number | The factor used in the falloff equation. |
slots |
Object | A dictionary that contains the pc.SoundSlots managed by this Component. |
Extends
Methods
addSlot(name, options) → {pc.SoundSlot}
Creates a new pc.SoundSlot with the specified name.
Parameters:
Name | Type | Description | |||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
name |
String | The name of the slot | |||||||||||||||||||||||||||||||||||||||||||||
options |
Object | Settings for the slot
Properties
|
Returns:
The new slot.
- Type
- pc.SoundSlot
Example
// get an asset by id
var asset = app.assets.get(10);
// add a slot
this.entity.sound.addSlot('beep', {
asset: asset
});
// play
this.entity.sound.play('beep');
pause(nameopt)
Pauses playback of the slot with the specified name. If the name is undefined then all slots currently played will be paused. The slots can be resumed by calling pc.SoundComponent#resume.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
String |
<optional> |
The name of the slot to pause. Leave undefined to pause everything. |
Example
// pause all sounds
this.entity.sound.pause();
// pause a specific sound
this.entity.sound.pause('beep');
play(name) → {pc.SoundInstance}
Begins playing the sound slot with the specified name. The slot will restart playing if it is already playing unless the overlap field is true in which case a new sound will be created and played.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The name of the pc.SoundSlot to play |
Returns:
The sound instance that will be played.
- Type
- pc.SoundInstance
Example
// get asset by id
var asset = app.assets.get(10);
// create a slot and play it
this.entity.sound.addSlot('beep', {
asset: asset
});
this.entity.sound.play('beep');
removeSlot(name)
Removes the pc.SoundSlot with the specified name.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The name of the slot |
Example
// remove a slot called 'beep'
this.entity.sound.removeSlot('beep');
resume(name)
Resumes playback of the sound slot with the specified name if it's paused. If no name is specified all slots will be resumed.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The name of the slot to resume. Leave undefined to resume everything. |
Example
// resume all sounds
this.entity.sound.resume();
// resume a specific sound
this.entity.sound.resume('beep');
slot(name) → {pc.SoundSlot}
Returns the slot with the specified name
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The name of the slot |
Returns:
The slot
- Type
- pc.SoundSlot
Example
// get a slot and set its volume
this.entity.sound.slot('beep').volume = 0.5;
stop(name)
Stops playback of the sound slot with the specified name if it's paused. If no name is specified all slots will be stopped.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The name of the slot to stop. Leave undefined to stop everything. |
Example
// stop all sounds
this.entity.sound.stop();
// stop a specific sound
this.entity.sound.stop('beep');
Events
end
Fired when a sound instance stops playing because it reached its ending.
Parameters:
Name | Type | Description |
---|---|---|
slot |
pc.SoundSlot | The slot whose instance ended |
instance |
pc.SoundInstance | The instance that ended |
pause
Fired when a sound instance is paused.
Parameters:
Name | Type | Description |
---|---|---|
slot |
pc.SoundSlot | The slot whose instance was paused |
instance |
pc.SoundInstance | The instance that was paused created to play the sound |
play
Fired when a sound instance starts playing
Parameters:
Name | Type | Description |
---|---|---|
slot |
pc.SoundSlot | The slot whose instance started playing |
instance |
pc.SoundInstance | The instance that started playing |
resume
Fired when a sound instance is resumed..
Parameters:
Name | Type | Description |
---|---|---|
slot |
pc.SoundSlot | The slot whose instance was resumed |
instance |
pc.SoundInstance | The instance that was resumed |
stop
Fired when a sound instance is stopped.
Parameters:
Name | Type | Description |
---|---|---|
slot |
pc.SoundSlot | The slot whose instance was stopped |
instance |
pc.SoundInstance | The instance that was stopped |