github_url: | hide |
---|
Inherits: :ref:`Node2D<class_Node2D>` < :ref:`CanvasItem<class_CanvasItem>` < :ref:`Node<class_Node>` < :ref:`Object<class_Object>`
Plays positional sound in 2D space.
Plays audio that dampens with distance from screen center.
See also :ref:`AudioStreamPlayer<class_AudioStreamPlayer>` to play a sound non-positionally.
Note: Hiding an AudioStreamPlayer2D
node does not disable its audio output. To temporarily disable an AudioStreamPlayer2D
's audio output, set :ref:`volume_db<class_AudioStreamPlayer2D_property_volume_db>` to a very low value like -100
(which isn't audible to human hearing).
- finished ( )
Emitted when the audio stops playing.
- :ref:`int<class_int>` area_mask
Default | 1 |
Setter | set_area_mask(value) |
Getter | get_area_mask() |
Determines which :ref:`Area2D<class_Area2D>` layers affect the sound for reverb and audio bus effects. Areas can be used to redirect :ref:`AudioStream<class_AudioStream>`s so that they play in a certain audio bus. An example of how you might use this is making a "water" area so that sounds played in the water are redirected through an audio bus to make them sound like they are being played underwater.
- :ref:`float<class_float>` attenuation
Default | 1.0 |
Setter | set_attenuation(value) |
Getter | get_attenuation() |
Dampens audio over distance with this as an exponent.
- :ref:`bool<class_bool>` autoplay
Default | false |
Setter | set_autoplay(value) |
Getter | is_autoplay_enabled() |
If true
, audio plays when added to scene tree.
Default | &"Master" |
Setter | set_bus(value) |
Getter | get_bus() |
Bus on which this audio is playing.
Note: When setting this property, keep in mind that no validation is performed to see if the given name matches an existing bus. This is because audio bus layouts might be loaded after this property is set. If this given name can't be resolved at runtime, it will fall back to "Master"
.
- :ref:`float<class_float>` max_distance
Default | 2000.0 |
Setter | set_max_distance(value) |
Getter | get_max_distance() |
Maximum distance from which audio is still hearable.
- :ref:`int<class_int>` max_polyphony
Default | 1 |
Setter | set_max_polyphony(value) |
Getter | get_max_polyphony() |
The maximum number of sounds this node can play at the same time. Playing additional sounds after this value is reached will cut off the oldest sounds.
- :ref:`float<class_float>` panning_strength
Default | 1.0 |
Setter | set_panning_strength(value) |
Getter | get_panning_strength() |
Scales the panning strength for this node by multiplying the base :ref:`ProjectSettings.audio/general/2d_panning_strength<class_ProjectSettings_property_audio/general/2d_panning_strength>` with this factor. Higher values will pan audio from left to right more dramatically than lower values.
- :ref:`float<class_float>` pitch_scale
Default | 1.0 |
Setter | set_pitch_scale(value) |
Getter | get_pitch_scale() |
The pitch and the tempo of the audio, as a multiplier of the audio sample's sample rate.
- :ref:`bool<class_bool>` playing
Default | false |
Getter | is_playing() |
If true
, audio is playing.
Setter | set_stream(value) |
Getter | get_stream() |
The :ref:`AudioStream<class_AudioStream>` object to be played.
- :ref:`bool<class_bool>` stream_paused
Default | false |
Setter | set_stream_paused(value) |
Getter | get_stream_paused() |
If true
, the playback is paused. You can resume it by setting stream_paused
to false
.
- :ref:`float<class_float>` volume_db
Default | 0.0 |
Setter | set_volume_db(value) |
Getter | get_volume_db() |
Base volume without dampening.
- :ref:`float<class_float>` get_playback_position ( )
Returns the position in the :ref:`AudioStream<class_AudioStream>`.
- :ref:`AudioStreamPlayback<class_AudioStreamPlayback>` get_stream_playback ( )
Returns the :ref:`AudioStreamPlayback<class_AudioStreamPlayback>` object associated with this AudioStreamPlayer2D
.
- void play ( :ref:`float<class_float>` from_position=0.0 )
Plays the audio from the given position from_position
, in seconds.
- void seek ( :ref:`float<class_float>` to_position )
Sets the position from which audio will be played, in seconds.
- void stop ( )
Stops the audio.