class_audiostreamplayer2d.rst 20 KB

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