class_audiostreamplayer2d.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/4.2/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.2/doc/classes/AudioStreamPlayer2D.xml.
  6. .. _class_AudioStreamPlayer2D:
  7. AudioStreamPlayer2D
  8. ===================
  9. **Inherits:** :ref:`Node2D<class_Node2D>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  10. Plays positional sound in 2D space.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. Plays audio that is attenuated with distance to the listener.
  15. By default, audio is heard from the screen center. This can be changed by adding an :ref:`AudioListener2D<class_AudioListener2D>` node to the scene and enabling it by calling :ref:`AudioListener2D.make_current<class_AudioListener2D_method_make_current>` on it.
  16. See also :ref:`AudioStreamPlayer<class_AudioStreamPlayer>` to play a sound non-positionally.
  17. \ **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).
  18. .. rst-class:: classref-introduction-group
  19. Tutorials
  20. ---------
  21. - :doc:`Audio streams <../tutorials/audio/audio_streams>`
  22. .. rst-class:: classref-reftable-group
  23. Properties
  24. ----------
  25. .. table::
  26. :widths: auto
  27. +---------------------------------------+------------------------------------------------------------------------------+---------------+
  28. | :ref:`int<class_int>` | :ref:`area_mask<class_AudioStreamPlayer2D_property_area_mask>` | ``1`` |
  29. +---------------------------------------+------------------------------------------------------------------------------+---------------+
  30. | :ref:`float<class_float>` | :ref:`attenuation<class_AudioStreamPlayer2D_property_attenuation>` | ``1.0`` |
  31. +---------------------------------------+------------------------------------------------------------------------------+---------------+
  32. | :ref:`bool<class_bool>` | :ref:`autoplay<class_AudioStreamPlayer2D_property_autoplay>` | ``false`` |
  33. +---------------------------------------+------------------------------------------------------------------------------+---------------+
  34. | :ref:`StringName<class_StringName>` | :ref:`bus<class_AudioStreamPlayer2D_property_bus>` | ``&"Master"`` |
  35. +---------------------------------------+------------------------------------------------------------------------------+---------------+
  36. | :ref:`float<class_float>` | :ref:`max_distance<class_AudioStreamPlayer2D_property_max_distance>` | ``2000.0`` |
  37. +---------------------------------------+------------------------------------------------------------------------------+---------------+
  38. | :ref:`int<class_int>` | :ref:`max_polyphony<class_AudioStreamPlayer2D_property_max_polyphony>` | ``1`` |
  39. +---------------------------------------+------------------------------------------------------------------------------+---------------+
  40. | :ref:`float<class_float>` | :ref:`panning_strength<class_AudioStreamPlayer2D_property_panning_strength>` | ``1.0`` |
  41. +---------------------------------------+------------------------------------------------------------------------------+---------------+
  42. | :ref:`float<class_float>` | :ref:`pitch_scale<class_AudioStreamPlayer2D_property_pitch_scale>` | ``1.0`` |
  43. +---------------------------------------+------------------------------------------------------------------------------+---------------+
  44. | :ref:`bool<class_bool>` | :ref:`playing<class_AudioStreamPlayer2D_property_playing>` | ``false`` |
  45. +---------------------------------------+------------------------------------------------------------------------------+---------------+
  46. | :ref:`AudioStream<class_AudioStream>` | :ref:`stream<class_AudioStreamPlayer2D_property_stream>` | |
  47. +---------------------------------------+------------------------------------------------------------------------------+---------------+
  48. | :ref:`bool<class_bool>` | :ref:`stream_paused<class_AudioStreamPlayer2D_property_stream_paused>` | ``false`` |
  49. +---------------------------------------+------------------------------------------------------------------------------+---------------+
  50. | :ref:`float<class_float>` | :ref:`volume_db<class_AudioStreamPlayer2D_property_volume_db>` | ``0.0`` |
  51. +---------------------------------------+------------------------------------------------------------------------------+---------------+
  52. .. rst-class:: classref-reftable-group
  53. Methods
  54. -------
  55. .. table::
  56. :widths: auto
  57. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------+
  58. | :ref:`float<class_float>` | :ref:`get_playback_position<class_AudioStreamPlayer2D_method_get_playback_position>` **(** **)** |
  59. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------+
  60. | :ref:`AudioStreamPlayback<class_AudioStreamPlayback>` | :ref:`get_stream_playback<class_AudioStreamPlayer2D_method_get_stream_playback>` **(** **)** |
  61. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------+
  62. | :ref:`bool<class_bool>` | :ref:`has_stream_playback<class_AudioStreamPlayer2D_method_has_stream_playback>` **(** **)** |
  63. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------+
  64. | void | :ref:`play<class_AudioStreamPlayer2D_method_play>` **(** :ref:`float<class_float>` from_position=0.0 **)** |
  65. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------+
  66. | void | :ref:`seek<class_AudioStreamPlayer2D_method_seek>` **(** :ref:`float<class_float>` to_position **)** |
  67. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------+
  68. | void | :ref:`stop<class_AudioStreamPlayer2D_method_stop>` **(** **)** |
  69. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------+
  70. .. rst-class:: classref-section-separator
  71. ----
  72. .. rst-class:: classref-descriptions-group
  73. Signals
  74. -------
  75. .. _class_AudioStreamPlayer2D_signal_finished:
  76. .. rst-class:: classref-signal
  77. **finished** **(** **)**
  78. Emitted when the audio stops playing.
  79. .. rst-class:: classref-section-separator
  80. ----
  81. .. rst-class:: classref-descriptions-group
  82. Property Descriptions
  83. ---------------------
  84. .. _class_AudioStreamPlayer2D_property_area_mask:
  85. .. rst-class:: classref-property
  86. :ref:`int<class_int>` **area_mask** = ``1``
  87. .. rst-class:: classref-property-setget
  88. - void **set_area_mask** **(** :ref:`int<class_int>` value **)**
  89. - :ref:`int<class_int>` **get_area_mask** **(** **)**
  90. 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.
  91. .. rst-class:: classref-item-separator
  92. ----
  93. .. _class_AudioStreamPlayer2D_property_attenuation:
  94. .. rst-class:: classref-property
  95. :ref:`float<class_float>` **attenuation** = ``1.0``
  96. .. rst-class:: classref-property-setget
  97. - void **set_attenuation** **(** :ref:`float<class_float>` value **)**
  98. - :ref:`float<class_float>` **get_attenuation** **(** **)**
  99. The volume is attenuated over distance with this as an exponent.
  100. .. rst-class:: classref-item-separator
  101. ----
  102. .. _class_AudioStreamPlayer2D_property_autoplay:
  103. .. rst-class:: classref-property
  104. :ref:`bool<class_bool>` **autoplay** = ``false``
  105. .. rst-class:: classref-property-setget
  106. - void **set_autoplay** **(** :ref:`bool<class_bool>` value **)**
  107. - :ref:`bool<class_bool>` **is_autoplay_enabled** **(** **)**
  108. If ``true``, audio plays when added to scene tree.
  109. .. rst-class:: classref-item-separator
  110. ----
  111. .. _class_AudioStreamPlayer2D_property_bus:
  112. .. rst-class:: classref-property
  113. :ref:`StringName<class_StringName>` **bus** = ``&"Master"``
  114. .. rst-class:: classref-property-setget
  115. - void **set_bus** **(** :ref:`StringName<class_StringName>` value **)**
  116. - :ref:`StringName<class_StringName>` **get_bus** **(** **)**
  117. Bus on which this audio is playing.
  118. \ **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"``.
  119. .. rst-class:: classref-item-separator
  120. ----
  121. .. _class_AudioStreamPlayer2D_property_max_distance:
  122. .. rst-class:: classref-property
  123. :ref:`float<class_float>` **max_distance** = ``2000.0``
  124. .. rst-class:: classref-property-setget
  125. - void **set_max_distance** **(** :ref:`float<class_float>` value **)**
  126. - :ref:`float<class_float>` **get_max_distance** **(** **)**
  127. Maximum distance from which audio is still hearable.
  128. .. rst-class:: classref-item-separator
  129. ----
  130. .. _class_AudioStreamPlayer2D_property_max_polyphony:
  131. .. rst-class:: classref-property
  132. :ref:`int<class_int>` **max_polyphony** = ``1``
  133. .. rst-class:: classref-property-setget
  134. - void **set_max_polyphony** **(** :ref:`int<class_int>` value **)**
  135. - :ref:`int<class_int>` **get_max_polyphony** **(** **)**
  136. 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.
  137. .. rst-class:: classref-item-separator
  138. ----
  139. .. _class_AudioStreamPlayer2D_property_panning_strength:
  140. .. rst-class:: classref-property
  141. :ref:`float<class_float>` **panning_strength** = ``1.0``
  142. .. rst-class:: classref-property-setget
  143. - void **set_panning_strength** **(** :ref:`float<class_float>` value **)**
  144. - :ref:`float<class_float>` **get_panning_strength** **(** **)**
  145. 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.
  146. .. rst-class:: classref-item-separator
  147. ----
  148. .. _class_AudioStreamPlayer2D_property_pitch_scale:
  149. .. rst-class:: classref-property
  150. :ref:`float<class_float>` **pitch_scale** = ``1.0``
  151. .. rst-class:: classref-property-setget
  152. - void **set_pitch_scale** **(** :ref:`float<class_float>` value **)**
  153. - :ref:`float<class_float>` **get_pitch_scale** **(** **)**
  154. The pitch and the tempo of the audio, as a multiplier of the audio sample's sample rate.
  155. .. rst-class:: classref-item-separator
  156. ----
  157. .. _class_AudioStreamPlayer2D_property_playing:
  158. .. rst-class:: classref-property
  159. :ref:`bool<class_bool>` **playing** = ``false``
  160. .. rst-class:: classref-property-setget
  161. - :ref:`bool<class_bool>` **is_playing** **(** **)**
  162. If ``true``, audio is playing or is queued to be played (see :ref:`play<class_AudioStreamPlayer2D_method_play>`).
  163. .. rst-class:: classref-item-separator
  164. ----
  165. .. _class_AudioStreamPlayer2D_property_stream:
  166. .. rst-class:: classref-property
  167. :ref:`AudioStream<class_AudioStream>` **stream**
  168. .. rst-class:: classref-property-setget
  169. - void **set_stream** **(** :ref:`AudioStream<class_AudioStream>` value **)**
  170. - :ref:`AudioStream<class_AudioStream>` **get_stream** **(** **)**
  171. The :ref:`AudioStream<class_AudioStream>` object to be played.
  172. .. rst-class:: classref-item-separator
  173. ----
  174. .. _class_AudioStreamPlayer2D_property_stream_paused:
  175. .. rst-class:: classref-property
  176. :ref:`bool<class_bool>` **stream_paused** = ``false``
  177. .. rst-class:: classref-property-setget
  178. - void **set_stream_paused** **(** :ref:`bool<class_bool>` value **)**
  179. - :ref:`bool<class_bool>` **get_stream_paused** **(** **)**
  180. If ``true``, the playback is paused. You can resume it by setting :ref:`stream_paused<class_AudioStreamPlayer2D_property_stream_paused>` to ``false``.
  181. .. rst-class:: classref-item-separator
  182. ----
  183. .. _class_AudioStreamPlayer2D_property_volume_db:
  184. .. rst-class:: classref-property
  185. :ref:`float<class_float>` **volume_db** = ``0.0``
  186. .. rst-class:: classref-property-setget
  187. - void **set_volume_db** **(** :ref:`float<class_float>` value **)**
  188. - :ref:`float<class_float>` **get_volume_db** **(** **)**
  189. Base volume before attenuation.
  190. .. rst-class:: classref-section-separator
  191. ----
  192. .. rst-class:: classref-descriptions-group
  193. Method Descriptions
  194. -------------------
  195. .. _class_AudioStreamPlayer2D_method_get_playback_position:
  196. .. rst-class:: classref-method
  197. :ref:`float<class_float>` **get_playback_position** **(** **)**
  198. Returns the position in the :ref:`AudioStream<class_AudioStream>`.
  199. .. rst-class:: classref-item-separator
  200. ----
  201. .. _class_AudioStreamPlayer2D_method_get_stream_playback:
  202. .. rst-class:: classref-method
  203. :ref:`AudioStreamPlayback<class_AudioStreamPlayback>` **get_stream_playback** **(** **)**
  204. Returns the :ref:`AudioStreamPlayback<class_AudioStreamPlayback>` object associated with this **AudioStreamPlayer2D**.
  205. .. rst-class:: classref-item-separator
  206. ----
  207. .. _class_AudioStreamPlayer2D_method_has_stream_playback:
  208. .. rst-class:: classref-method
  209. :ref:`bool<class_bool>` **has_stream_playback** **(** **)**
  210. Returns whether the :ref:`AudioStreamPlayer<class_AudioStreamPlayer>` can return the :ref:`AudioStreamPlayback<class_AudioStreamPlayback>` object or not.
  211. .. rst-class:: classref-item-separator
  212. ----
  213. .. _class_AudioStreamPlayer2D_method_play:
  214. .. rst-class:: classref-method
  215. void **play** **(** :ref:`float<class_float>` from_position=0.0 **)**
  216. Queues the audio to play on the next physics frame, from the given position ``from_position``, in seconds.
  217. .. rst-class:: classref-item-separator
  218. ----
  219. .. _class_AudioStreamPlayer2D_method_seek:
  220. .. rst-class:: classref-method
  221. void **seek** **(** :ref:`float<class_float>` to_position **)**
  222. Sets the position from which audio will be played, in seconds.
  223. .. rst-class:: classref-item-separator
  224. ----
  225. .. _class_AudioStreamPlayer2D_method_stop:
  226. .. rst-class:: classref-method
  227. void **stop** **(** **)**
  228. Stops the audio.
  229. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  230. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  231. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  232. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  233. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  234. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  235. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`