Skip to content

Files

Latest commit

 

History

History
321 lines (220 loc) · 13.9 KB

class_audiostreamplayer2d.rst

File metadata and controls

321 lines (220 loc) · 13.9 KB
github_url:hide

AudioStreamPlayer2D

Inherits: :ref:`Node2D<class_Node2D>` < :ref:`CanvasItem<class_CanvasItem>` < :ref:`Node<class_Node>` < :ref:`Object<class_Object>`

Plays positional sound in 2D space.

Description

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).

Tutorials

Properties

:ref:`int<class_int>` :ref:`area_mask<class_AudioStreamPlayer2D_property_area_mask>` 1
:ref:`float<class_float>` :ref:`attenuation<class_AudioStreamPlayer2D_property_attenuation>` 1.0
:ref:`bool<class_bool>` :ref:`autoplay<class_AudioStreamPlayer2D_property_autoplay>` false
:ref:`StringName<class_StringName>` :ref:`bus<class_AudioStreamPlayer2D_property_bus>` &"Master"
:ref:`float<class_float>` :ref:`max_distance<class_AudioStreamPlayer2D_property_max_distance>` 2000.0
:ref:`int<class_int>` :ref:`max_polyphony<class_AudioStreamPlayer2D_property_max_polyphony>` 1
:ref:`float<class_float>` :ref:`panning_strength<class_AudioStreamPlayer2D_property_panning_strength>` 1.0
:ref:`float<class_float>` :ref:`pitch_scale<class_AudioStreamPlayer2D_property_pitch_scale>` 1.0
:ref:`bool<class_bool>` :ref:`playing<class_AudioStreamPlayer2D_property_playing>` false
:ref:`AudioStream<class_AudioStream>` :ref:`stream<class_AudioStreamPlayer2D_property_stream>`  
:ref:`bool<class_bool>` :ref:`stream_paused<class_AudioStreamPlayer2D_property_stream_paused>` false
:ref:`float<class_float>` :ref:`volume_db<class_AudioStreamPlayer2D_property_volume_db>` 0.0

Methods

:ref:`float<class_float>` :ref:`get_playback_position<class_AudioStreamPlayer2D_method_get_playback_position>` ( )
:ref:`AudioStreamPlayback<class_AudioStreamPlayback>` :ref:`get_stream_playback<class_AudioStreamPlayer2D_method_get_stream_playback>` ( )
void :ref:`play<class_AudioStreamPlayer2D_method_play>` ( :ref:`float<class_float>` from_position=0.0 )
void :ref:`seek<class_AudioStreamPlayer2D_method_seek>` ( :ref:`float<class_float>` to_position )
void :ref:`stop<class_AudioStreamPlayer2D_method_stop>` ( )

Signals

  • finished ( )

Emitted when the audio stops playing.

Property Descriptions

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.


Default 1.0
Setter set_attenuation(value)
Getter get_attenuation()

Dampens audio over distance with this as an exponent.


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".


Default 2000.0
Setter set_max_distance(value)
Getter get_max_distance()

Maximum distance from which audio is still hearable.


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.


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.


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.


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.


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.


Default 0.0
Setter set_volume_db(value)
Getter get_volume_db()

Base volume without dampening.

Method Descriptions

Returns the position in the :ref:`AudioStream<class_AudioStream>`.


Returns the :ref:`AudioStreamPlayback<class_AudioStreamPlayback>` object associated with this AudioStreamPlayer2D.


Plays the audio from the given position from_position, in seconds.


Sets the position from which audio will be played, in seconds.


  • void stop ( )

Stops the audio.